{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1 SymPy前言\n",
    "是一个用于符号数学的Python库。它旨在成为一个功能齐全的计算机代数系统（CAS），同时保持代码尽可能简单，以便易于理解和易于扩展。SymPy完全用Python编写。\n",
    "## 1.0 安装\n",
    "``` shell\n",
    "pip install sympy\n",
    "```\n",
    "## 1.1 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IPython console for SymPy 1.3 (Python 3.6.5-64-bit) (ground types: python)\n",
      "\n",
      "These commands were executed:\n",
      ">>> from __future__ import division\n",
      ">>> from sympy import *\n",
      ">>> x, y, z, t = symbols('x y z t')\n",
      ">>> k, m, n = symbols('k m n', integer=True)\n",
      ">>> f, g, h = symbols('f g h', cls=Function)\n",
      ">>> init_printing()\n",
      "\n",
      "Documentation can be found at http://docs.sympy.org/1.3/\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sympy import *\n",
    "init_session()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "执行一些简单的SymPy语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = Symbol('x')\n",
    "limit(sin(x)/x,x,0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2 介绍\n",
    "## 2.1 什么是符号计算？\n",
    "符号计算以符号方式处理数学对象的计算。这意味着数学对象能够被精确地表示，而不是近似地表示，并且相关变量的数学表达式以符号形式保留。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACEAAAASCAYAAADVCrdsAAAABHNCSVQICAgIfAhkiAAAAa5JREFUSInt1c2LzlEUB/CPiZK3xxiNWVAyGRNKSdMUGxZ2Nv4C/4CysGcjbMSCZEH5B7Dz0sxuZqOMLOQhGSkabyVvGTIW9zzN08/vPs81q1n4bk73npf7veeecy6LEGcxhlf4jo+Ywgn0LSDeRlzFa/zANM6jt91oScVpFg/wGG+xEqPYE4FGg2AJBjGJftzCE4xgP5rYiw91jsszAU9hDpcKCcCd8Dla2T8X+5f/IRbYFY73Cu23hP0L9FR0q/EFX6VM/2WQw6GQjwrtD4S8i98V3WdMYIX0vJZmghzHKjSketgXBM4UktgW8mlG/wwHMYSxTiQ2tK1v4wjeFZJohPyU0bf215J/jgGpcwZwWHrjKewuJNENra6c60SihRnckFLXh+uFh7Ru2sjo17TblRbmS2l27MD6AvtmyKGMfmvIXM1kMSOlr7eboTSourXoN9Gi7RiWaqCKHvPDaqLmsGEsq/Fb0LA6hp/S33EFp6W5/zyc3mB7xWc6dJtr4g2az97NiDce66bMX7QTF/EQ7/FLKpz7OIl1NT6dSMAmXIsLzEq1dSET6z8WB/4AQv5i5ySUdAIAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$3.0$$"
      ],
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用内置的Python函数来计算平方根\n",
    "import math\n",
    "math.sqrt(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   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XH/fos8KCq7/+IPcSu/v6rkZS24XSzRUutiTBQ8jHFROQe9xvkLk1ALHxbmQRenAdL5CrqVokDqtBsqx9kJN7IOY7wvuBr4DnEFdzrerZA0ncTPDJ3oC4y5XI1z+7kSTMtcji3qF2GJEl3m9fHGhTpeWtDP01RGKTZUiwexj4HUlflwdkk3C7ckTB4w/uzkn1AtkIXJIvcVxVBdTN1E/UCehqS1KeZsjJshlxQ3cjXzqZLrq9/mzHC+AR5GuXvcii24ycYK1idG+JfJu6XfX6BYmHg15HR+AFJByoRubjPiS2zRrkiyiiiCKKKKKIIooo4r/GPxuAPp/TJZNPAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$2.8284271247461903$$"
      ],
      "text/plain": [
       "2.8284271247461903"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.sqrt(8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "符号计算的真正力量的地方 - 符号结果可以象征性地简化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACwAAAAbCAYAAAAH+20UAAAABHNCSVQICAgIfAhkiAAAAZ5JREFUWIXt1j1oFEEYxvGfMVolhZ4EC9sI6WwNqRSVCFYmaS20iAgSSBEIBCxEi1jFD7ARm1gJVgbsUohVwCKIKBbBwkIQExshH2ixU9xtsnezcUYR7g/DDjPvPM/77s7OLl3yciCzfj9+ZPZIyhgu/Osk6vAAh1MK9qQUK3EwtM2UojkTHsabjPrJuYtGatGcd7iBb6lFmxNu4Bpe4BN+YgOvcVW94gbxoWIumc8kfuELFhWP9AnWw/hz8ef2NE7m9jmDS3ZXeByfg9jlyIQf/yWfSmaD0P2msR7cxmgp9ijuJPRpIXa/bIXrdtPYeZzGeCn2IpYidWN8atOLVUXl5c/sKXzVWvhD+zt92vnU4l4QeVkxv4aR0D+EhUw+UdwMIu8Ve3MvFjAf+ufs74WJ8enIjSDyTvEGV3EWH0N/Hn2ZfNoyFURWMdAhthffMYRHGX0qmQkib3Escs0inuF6Zp9dzAWRFfX20kRYdyKzT8sn8AqeYkdxcG/sEb8WYsr045Xil7ITf+LTwi1F1e3acpv1RyKSTeHTpct/zW/Ik3njsPGUkQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$2 \\sqrt{2}$$"
      ],
      "text/plain": [
       "2⋅√2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sympy\n",
    "sympy.sqrt(8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.2 神奇的符号计算\n",
    "上面的例子展示了如何使用SymPy精确的计算无理数。但是，符号计算系统，远不止于此，CAS还能计算带变量的符号表达式。在SymPy中，变量时使用$symbols$定义的。\n",
    "\n",
    "让我们定义一个符号表达式，表示数学表达式$x+2y$。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEAAAAAWCAYAAABwvpo0AAAABHNCSVQICAgIfAhkiAAAAnJJREFUWIXt11uITVEYB/AfhgeUu5A8KZ5cHjQvlFxSSsrlgRe7SIpEEiklD4YilFxL48GDS8ilNEkYE0lRbi/SRLmkDAm5joe1RmfOme3sOWdy0PzrdPb+1vr/179vf+vba9OJvxYDsASn8Rif8A7XsRhdK2ftz2AZmvEcR1GDw3gb4yfRpWLu2oFEMDy5nbwpmKXwSQ/B06g5t0xvBeJ1UXhOXrwLauPY1nIXzYjLOIcfefGX2B+vJ+eNrRE8rknRHIXPuJa26Fh8x0N0y4nviMIHi/suQKK0Cvgd1kbNnXnx6hg/kcKrwzeM+Z14bRRJ4v2GeH9MaY0n0bEJqMK9qDkjb6w7PgpbJB/zI2d3sQWGCx23ESsi6SJ6lGg40bEJ2B71LqSMX43jw3JivfAMr9AnyyI1UaQZDeiZ0VxjDi/LrzajbgtWRt4j9E+Zs0VhH9umdVX/QlWKyOuc68VCWWXBLvTNi43DbBwREpSLuxl1YblQvg8xFW9S5jXE/2qcwmisxo3ooSgWCJ33hZC1fe0w2RYS5W+BVVHjHgYXmdtP8H813l8SGvv4LAvNxJe40CCh1L4KWSwVifISsC7y72BgRs4DfMDCyN2bhTRRKPUnGBpj86LAmex+C5AoPQEbI/e29D3fFg5E3nthO6dyW3rAWJwXztrThfInHDdvC3t4EurbYaJcLMJmoXzrhQaYj0ZtN9IGLEVvYf+n9QswUjhdNWn7gDBNyObNTLYLkSitAjYp/ha5ksKdFMdv+Ue+FzoaZ4XKmVBpI5VAS+PbU2kjfxIjsB6HhI+d+7If3v4LLBWeehOOa30M7kQnOpGOn+VprJwVZhXBAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x + 2 y$$"
      ],
      "text/plain": [
       "x + 2⋅y"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x,y=symbols('x y')\n",
    "expr=x+2*y\n",
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们上面编写的代码表达式，除了$x、y$不同于普通python变量，其他都一样。但是，区别于普通形式，这里没有输出计算结果，而是输出了数学表达式。现在我们试着操作这个表达式，看看有什么效果？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGMAAAAWCAYAAADU1CLnAAAABHNCSVQICAgIfAhkiAAAAvNJREFUaIHt2EGoFVUcx/GPZS1KMMskQ1oVudJaiAYJt1SEQIrSRW0cMCQoQlFRgkAirMBFYZQiyBN0YYSKFUhEZfowREiwclHEpcAUJVOxULPX4n8eXsc3vrkz970beL8wzMw553/O78//nPOfOfToUYJ78CJ24Wf8jbM4gCW4pXvS2mYhNmA/zmEA27qqqE1eEqKPYzvewhb8mco/xpiuqWuPI0LzeRzTxWBkafBGm3ZPYoHrV8B9+DX1+VxNbWXJVPNhkCfwkJg8DQXByDv6eWr4bK58DPpS3dsVBbXLl/gE/+bKT2Bjem7k6lYIjSsK+nwYF/FNZySW5iv8JLQVkg/GKuH8m7i1pXw9FmMz1nROY2Uup/s/ufID6T6rwG6D8OuVkRA1EvSJCGbp/bX0vkO1pJmpt8TzjMXR1Of8XN1t+EtsY3kWJZv3KoyZ6ZwPDW3kjCniy6UpZtAA9uL2ioNnOhuM9am/zwrq96X6+1vK7sRvOInxFcbMdCkYxJfLQLr6cUdJu2aLXZmrr6ygxKvJ7hjuLmizzvV57x3XrvYb0SypvaoPDQXBGFtgcKrleYlY+mV4F3flyh7B09gqHG3lSMl+4WWxxfyIOfijoF1/us/ETkzFchxMGoZjJH1om+dFEv9dRPDDmv1l6i/xZamPo5g0TNsJQv++9P4FruDRGuNnurBNPYVLwul7xXZwWcyuqmTqObI62X+HiSVtfsAFvJBsP6g49iCZUQ7G42I7+gWTU9nCZLi7xuCZ6o68nmwPK84RQ7HJ1T/eU23aDkVmFIIxmDOm41Nx9jNPbFHEkcNhsV/OFmcro8VivCG2mP0ieedpGjqB9mMpxol8UZRfRotn0kWcIMBjrmo/jZXwoPirPYNpQ3Q0V0Ty24pCMtVm1VrDf8l8XWA7O9Uf0pnzq0y9lbHWjf1o1tT3v2aPWFEzui3kZmcwab/fbSE3Kw+IM7PN4iDwe+V/VHt0mKViNZzBR649CunRo0ePHp3hP4Kn6TFLoo+XAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x + 2 y + 1$$"
      ],
      "text/plain": [
       "x + 2⋅y + 1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABsAAAAWCAYAAAAxSueLAAAABHNCSVQICAgIfAhkiAAAAYJJREFUSInt1D9IVlEYBvCfZksFYoVIg2uuDkKLS0tDuCQuLQaFBEkoDkkQhEMhtIQhRCAtLRIEQVtDf8whggaVFgcpEERIRTTyTzWcV7h93e/jfvB9tPjA5dz7vO9znnPe897Df8IpXMMLLOIHNjCDq2ispdl1/MYynuE+prAe/HM01MrsPHr8u4M2fA3D3lqZVcLtMJvIcCPBjZTRnMVPvDsgip7Dbox7GW4mxnNlNBM4gsGCHqAJc9IuLmT4o9iWSlyKvsh/WI0RPAjhq5zY24idyXDH8Q0raK7G6GZM9gUnc+L3In4pw40Hd6UaoxshWpA6Mg8XI2c8vjuwg1lV/CZDMckcWivkteCXVE54jX10FjW6FUafcbpA/gK2cDl0k0WN7oTgk/wzysPj0GxitZKuKfPejzGpDO+l5ijFEp6WcB8wgBMYxvciK7wbK6z0vMnRdUfsoxreneXwUqpGV72NDpriUb0M2jGKJ9JFO49j9TIbkHazhml/X1WHqD/+AD1fXtT6FituAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$2 y$$"
      ],
      "text/plain": [
       "2⋅y"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr-x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在上面的例子中，当我们计算$expr-x$时，我们得到的是$2*y$,而不是$x + 2*y - x$。这里表达式$expr$中的$x$和$-x$自动的抵消掉了。这就像$\\sqrt8$自动转换成$2\\sqrt2$一样。但是并不是所有情况都会像这样化简的。比如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFoAAAAXCAYAAACLbliwAAAABHNCSVQICAgIfAhkiAAAA3BJREFUaIHtmHtoT2EYxz9zy0zNPRZL0fCPSy5LmRYrpaRc/pg/OGxJbYQlrGR/uRSh5FoaJcaYLKUlmbZci3L7B7nEsDISC2P+eJ7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VORK5CYII=\n",
      "text/latex": [
       "$$x \\left(x + 2 y\\right)$$"
      ],
      "text/plain": [
       "x⋅(x + 2⋅y)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x*expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在这里，我们可能期待$x(x+2y)$ 转化为$x^2+2xy$，但我们看到表达式确没有像我们预期的一样。这是SymPy中经常会出现。除了明显的简化，如$x−x=0 $和$\\sqrt8=2\\sqrt2$，大多数简化不会自动执行。这是因为$x(x+2y)$和$x^2+2xy$，两种形式在不同情况下都很有用。考虑到这样的情况，在SymPy中，有从一种形式到另一种形式的功能。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFYAAAAaCAYAAAAtzKvgAAAABHNCSVQICAgIfAhkiAAAAvBJREFUaIHt2EuoVVUYB/CfaQ3U6OGDimiSUERlDsKJgpggBBH0GNigdigRFFKIpEJwRz5QsSyUCuI2aGBFhSKUNMhIigwMLJuIiIImQlph4vM2WN/Ve4/nnL3P3tt79Hb+sDhnr7W+//p/397fetHDNYnl2I2/cRzb8GBXFY0SfI0XpWA+hC/wB27vpqjRiIm4gCe6LaTbuKFmvpuD88+aefMwCYukjNmP0/gL32Oh+v0ccWzBHowd4XFfxgCO4GOswoc4GfWfYcwIa6oNa3EU00raZ1IQ5pSwnStNP41f5h04FLxPl9RVC3aEiKca6segP9pWN7Fbj2N4oMLYmfKBbYcVwftOQ30nvi6J5yUtxrgPZ/BdKxHTpcVnn+HpvD6I329is1H1oHL1Ars0eDc01Hfi68yo+7TFGDtwHg+3E9IfJFk8D77xLa5MtU3SHnaulHaDZWK7AVogU39gx2Fv8M5v0t6vmK834l9pWmnEs2Hzdp6Yu6VV9SBeDaOvcFOTvgMtSl/eIE2QqT+w64Jze4v2TnzdGe13DambgMNSxt5SRNAql4O0C+OLGHWAg1q/lGalv8QYi8P2d+0PLEV9XenKOXmN4V/8JYxrQXJ8yP+FUhrUibdwa0PdI3gSH0mBH4pfOuR/RUrNfXhM+311UV93xe9MfI778Tp+kDTnYgEuSlunAWwuYlQDMvVMBa8Fz15Mzenbia+3Rd+d8fyNtPjNKCLqcZwNUVOkNDonvZ2rjUz1wL4RHHswOadvGV9/wyk8F+NsKiJqlpQGB3Bn1D0TBF8WIaiITLXAvhn2P8u/BCrr63vR5x9pCsm9bJouHf+O4t6Gtt1BNjuPpCIy5QP7Qtiel/arfU1KFn2r+Pq8ywvdojxR06SrvhOab3DnBdGPeUQVkSkf2D75O4tvVfd1drT/5Dq+e7gWsVVasB7ttpDRhMEF691uCxkNuAfL8IF0yfKr+g9L/0u8JH2lJ/CJ4cfZHnrooYceuoT/AHeD8Jy7V0p7AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{2} + 2 x y$$"
      ],
      "text/plain": [
       " 2        \n",
       "x  + 2⋅x⋅y"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expanded_expr=expand(x*expr)\n",
    "expanded_expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFoAAAAXCAYAAACLbliwAAAABHNCSVQICAgIfAhkiAAAA3BJREFUaIHtmHtoT2EYxz9zy0zNPRZL0fCPSy5LmRYrpaRc/pg/OGxJbYQlrGR/uRSh5FoaJcaYLKUlmbZci3L7B7nEsDISC2P+eJ7td/bu3H6/nZ+xfp/69TvnfZ7n+zznPe973vccSPBfcQL4AKR0diGdzGSgGciLh/gU4DewPh7iITIQyAcqgKdAI/AZqEE6pltIeSqAOqBvSHqtVAGfgOSwhUNmFTLa3gInge3AMaT2ZqAcSAohzzTVKw5Bq5UMZDQfCVPUAwu5iOwYYmcB82g/cocCr1R3YQdqs/MEeAl0b2kwk1ZpwgVGexJQqrYdtvYVaitzSRitXjy5ClQiA8POO+CQHmcbtiKkxiIXzTHAd+C60X4aSAdy3IqZAPwCHmO7G8BuTWiO3LtAE+6LYLR6fljEPqK92KC6e4z2TG0/6xJXhVz/eKM9R+N2eSUtVSdLz4v1vIy2MyBFkzzwEotCLwgW4Xd0D+QamoE5hq0n8A15tJgs1ph9DrZUtd32SjwcWZFfAIUacBnoZfhlqK3KSywKvSBYhN/Ru1Tzkou9Wu1ptrYU4DXwHulUJxqRx5In21W8GagF+jj4TCcyMsPQM3lhiwnyKw2gabJGY58AA1x8ttF+ndlJ21nqxBtkxgMybZyotx3nIdPHpFH/e3ski0bPZC/Qz2ibCMwHjiM3ws79AJp2CpBp/xiYDXx08avV/0zgPDAWWAfc0DrcSCbSR47kIitzHXLXDrr4pam9xkssCr0gWITz6FirOg+AIT6+/ZH6q/X8CrLAT/KI6aYxz9wc5gI/tIDByJT6idxFkyTktbvewRaLXhAsOt7RG1XjHjAoYMwj4CuwRGMP+PiPU79zTsYZyJR+DgzTtkUacMFFsFzto0PS88OiYx29RePv4v5MduKwxn1BBpZf7HL1LzQNE5BX0TpglGG7o0FZDoK5aisISc8Pi9g7epnGNiH75RKHn+USu5TIopsfINcpzTPC3jga2YY00H7jDZHN900HWy+NvRWSnh8WsXd0Cf47l2susVlE9sV+30NSkUUw1lnrymYtwmtx+N+5iCyAUwP4rib2GetJb+QDSmXYwv8ILQvg/gC+ycjXwfJ4FTMT2ErX+fCfDmwCjiIfjR4S7CVrHPKIGhmvwroaK5FR3ACcoe3rd4IECRL8Lf4AaqETEmMl7lcAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x \\left(x + 2 y\\right)$$"
      ],
      "text/plain": [
       "x⋅(x + 2⋅y)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(f=expanded_expr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.3 符号计算的用途\n",
    "像SymPy这样的符号计算系统的真正强大之处在于能够象征性地进行各种计算。SymPy可以简化表达式，计算导数，积分和极限，求解方程，使用矩阵等等，并且可以象征性地完成所有操作。它还包括用于绘图，打印的模块(如数学公式的2D漂亮打印输出，或LATEX)，代码生成，物理，统计，组合，数论，几何，逻辑等。下面我们来看一些比较典型的案例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "x,t,z,nu=symbols('x t z nu')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALsAAAAWCAYAAACYEu1aAAAABHNCSVQICAgIfAhkiAAABdhJREFUeJztmmtsFUUUx38tD2nQFBWfQblGbACN+FYSTHwQJMRoIkrkk1eJxKAYNWqgSvSLqCiCUVMRNGBCeFgjCYkajNL6IAhFibUSJZCCwoWCBTVaitTrh3Mm3Tvd193ubmmyvy/bnTlzZjr/2ZmzZy9kZGSE4h6gExjpKHsd2AmcVaavHFAElscxMOV9oA0Y2gsfVyPjmhHLiNIhTl3S5KTWqwJoApbq/ZPAQeDiCL5yxLvYrwH+A56IwddHQAE4NQZfaRCnLmnRL/SaBPwLzAH+RAYdhUHAaOC8mMa1ATgKVMXg6zrkQayNwVdaxKVLWvQbvTYBJ4DJSTiPQA2yS7wTo88dwB5gQMT2eUSAm2IaTxhONl28SEWvSg/DqcAnwGHgOBLr1eIu9C3AOPXV5uHvDuBz5GjpBPYDjcAsh00O9zDGWZ4DVuu4jiFH9e0u/T2AHOVrPMazQX3eZZVXaD9F4CWrbjVwITDRw2caxK0LyC64BtiHaFNA5meai+004EvgD6ADaAbmAqe42IbR3NAneg0AVmnjnUAdsBj4WctWWPbjkKPnPmAdIoTNTG1bQJ7c+cAyYAuw1WGXw3+xb0RE2wws0rEcA7qAm602TciO5vWiM07b/UTpQlmofbntMBO17lUPn0Hkib6zJ6ELwI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qbugTva7VAR5AJviw/kNLgFu9GgXwEPLDnN3IE90OfA88DZzmsMsR32IfjPwP3zrKRmnZEST3bGM+Qmx2qatGdlmv9F8Y8kTPsyehi2E8ctS3IaHCfiSld7eL7b1IbP0X8kGvBcnn2y+XYTU3nIx69SvmIpNxZQy+ZuO/i2T0nkyvXjAEyRKs76WfKmS3q+/1iDL8SFyvqL/g6w+cAL5DfqTUhBz/UbgEiWkX4J3rz+g9mV4ZGRkZGRkZGe78D5YUPvfEkPQ2AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$e^{x} \\sin{\\left (x \\right )} + e^{x} \\cos{\\left (x \\right )}$$"
      ],
      "text/plain": [
       " x           x       \n",
       "ℯ ⋅sin(x) + ℯ ⋅cos(x)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导数\n",
    "diff(sin(x)*exp(x),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE8AAAAWCAYAAACBtcG5AAAABHNCSVQICAgIfAhkiAAAA89JREFUWIXt11uIVlUUB/DfaJpiYfcoKj/IRCOy6A72UImJRA9KQS9dIaLyRSJsIuqpIhKLArELWBBqGBlBhRE2UWFeKhKTECO7jU02SpGXvHw9rH2YM8dzvk8/T4Qyfxi+2Wut/d97r7PW2mszhP8Nt2APxuVkz2MTTj9MrgaaWFTHxhJeRx/GHAHHZWJf99Syoxy6sBYvp/FD+A3nd8DVUK/zLscBzKmB62304oQauAZhGvZiLv4Um+4EIzARZ9W0rxXYgdE1cF0pPmx3DVwH4XPsw/T/grwDTBBR91KNnBuxBcMzwbAKw1l4H9vwj6hh3fmJOVyPyYmrr4LvZnwkQn8PfkUP7s/ZNJSnbV7ewJK0r92iZNxUst7doqQsrdjPisQ5syDvSus08XRBtwTnYWoFp+FYnCZvwgI8h++S7LWC/WSRGndguXB4Efemub0iEp7EK1iNNTm7htbOWyk+zirMT3vZjf24rjBnrciEqoticpr3rcEBMS+tVRaxU5Pu2QpOLyaDp3BcTj4CnyXdhUk2Dr/g0TS+WKTKtQXOdSLazihZ77Tc/w2tndfE4wXdjUn+Xk42Rjhufcl6eSxKc+9M4+40Xqo8I8cm/eoysqvE4ZdXLJZF0F04RdSAhQWbN/FpQbYOf+PkqlMkNLR23g/Ky8YWkcYZJiT7FW3WOwe7Eu+Dac4HGNlizi5szQb56Jotcn4nniiZeFH67UI/JpXY3Foie0OkwwbxVXtEFP/eYpNl+FqkWhE/4Zrc+NT0u70N38+iJM3FC+LSmylqfBX6cWaZos9AerT6qyyYLXC7qFX7E8cBUcPybU1D+wujDB8nfYZL0vidQ9jXHAPnmngI9v34qygclQh6DoHgSHASZoimej/+MFALG+px3tlpXCwfRdwmPmJvsl/Qxn5Yst9cVIxOBBvaENSJV9Oas9K4oR7ndYksalUWZoj0XC+ekRtFo98q+ialdd7KBNmtsgvfiJu02PtkmKK8YLfDdINra4Ys4nZ2wNkKTXwibvLxJfopWCZq3jTh5MfSHou9XR5Xp9+VZcrsmdXEh6LIzxc36Gb8eJiHyLBD3FDLRI80T1z3TdGPjUh2DfVEHpGSTTxQkGd9aa+D399r0pxiq5VhsWiBzq3Qu0Iccqtw5DYR2gtxQ9WkNrhPPKy/F1HWj6/wME7M2TXU57yR4gxf5GTjk2y76EmLyJrgVSW6sSI7q9q4Yw6PCGdcWgPXbK2j8pjDKNFAv3uEPKPFW3xZUdHJBXC0YB++xPGitu7tkOcC8bx8RtTLIQxhCEcv/gWDOxgVx9XeSwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$e^{x} \\sin{\\left (x \\right )}$$"
      ],
      "text/plain": [
       " x       \n",
       "ℯ ⋅sin(x)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 积分\n",
    "integrate(exp(x)*sin(x) + exp(x)*cos(x), x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE8AAAAdCAYAAADrcjF6AAAABHNCSVQICAgIfAhkiAAAA2RJREFUaIHt2VuI1GUYx/HP6mpWW5ZGytJNgVJ0Ix0uChMssoMkRZJUoBeKZUGn7QBBYCF2UVfagYoyCCsqi6DaDjeRZTdBBzMhIiyiKCKzk2XHi+cdHf47/5n3P7uz08p8Ydj5P+/zvL/3ec//WXr06AZ9Ff2PwE9d1J/QLMV53W7EROU+TO12I/4vTKrgOzl99nWoLROOKp13JrZ1qiEHO3dj5jhrno8/8BL+HcPPuPNwFzSfxDVd0B1T5mCogX0mVuEFfIa92IO3sVK1baHIkdiNGaOooxWz8Dc2pOeO5DOEuQ3sV4tl8DU2i6X9GH5M9ue0f5dbhS1txuayWrRzYXruSD4PldjPxkVGjshsfJkEL60qltiKJW3G5jKM78UtglHkMwnrcEHBPgPr22jY7UlsYxuxJ+A7TGnis1j+ATGvQfx0cRhtymzTiHz66woX4QwMihGpcSFeyRSo58/0968mPoeLve2bgn05nqqroxF78CDWYIdYUjVOxDKxV72BjxrELxYX/uebaNTTMp95YsTrp+39qm+U/dguRqrR69xc0Tm/ir2lnj58jlMydC5JGusK9luTfWWT2GfxC6Zl6LTKZz+7MD99n+LASVSFe5PQyyXls3Ea3hIdOFBXtgAfZ+rcmXSWFuxPJ/upJXHT8LPowBxa5bOfDbgnfT9X9Q3/uiS0U+trRu20W15nexS3ZGq9mOLnFOyfimV2SEnckhR3RYZGlXyck8SJThxo4lvk2iS0Q8yuVhyF3/F6ej5U3O0GM/W+EDOo/vowgH/EMitjkzgspreov2o++kUCJ+GBnIDEDUloO46tELdFXFQHcSVezYw7Oum9U7CflexPlMRNFteT4ZLyGu3mY7N4NVqT6X9bEnofx1QRcmDTH8JruDwzbmGKKw7w9XX1NYtb3aTu0eTjshR8XIbvHcn3Pe29Sk3FD+KE3S2Wbg43atwJjyT7opK4jWKmzyopz86nv8Q+jHfxVbNgrMBdqTFbxeZaZBceb1LHPjyDq8RhsbeFZo3axffDgr2W8Mn4xMgcLhY/rX3boM6xyAexp7Rirda3+zcz6pmffBdk+Nb4QCR5WMG+TOxpv+HmQtnpSeemkjrXGpt8xpU+cbJ3+h9C60UHHN9hnYOSnWLG9ujRo0ePivwH0EP9y8zE1PwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{\\sqrt{2} \\sqrt{\\pi}}{2}$$"
      ],
      "text/plain": [
       "√2⋅√π\n",
       "─────\n",
       "  2  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 积分\n",
    "integrate(sin(x**2), (x, -oo, oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 极限\n",
    "limit(sin(x)/x, x, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHYAAAAdCAYAAAB/lJiIAAAABHNCSVQICAgIfAhkiAAAAtZJREFUaIHt2j2oFFcYgOEn5qZTMCpBxFYhkCKFjYJwUfQaIViIFsHgBAMqggQsrIRFBCVCuohpgoU3lSAoGCzyIxFtAgZEEsVCREQEMVpE/I3FmYvm3h13ZvfMmYnMC8POHs7MfO9+s2fPd3boeCt5p0/bDnyBP/P32/E4WUQdVfkMazEPi7CsqGMP19PENIM5+Dfy1kbmYI24nhmeTV1gVhKN8kxgnTCSxNrayITw2dfm2bbEjuOXpoNIwLiaPduU2Hfz7UnTgdRMEs82JXYFLjQdRAKSeLYpsetxpukgEpDEs02JnY97TQeRgCSebUnsElzt0z4fX+KkUII9wgOcxzbtib8sRZ4kcO1JX8fuwdI+7TuEGu02JnEQ3+PvvP2E9pY0/SjyZHTXzGt1bD960if2u4L2VfjUzLt1IW4KwhtrjCs2RZ6M7pppaIFiFg7gk2nt8xT/5vyM03gxrf0Ojub745Hii8UwnkR2TZnYtViOTdPah50lPs1f3zj8NEBsTyK59tQ3FH+Mu/57Q32r+g02hsvC8DQRJ7SoxPKkvGumwbXiP/CPUKTDe3hu5vAziEP4SPgGnI0WXTxieTKka5XE3lDt34bjBec5hQ35/jjOVYgBdguzy7/wecVjUzKqJ5Fde/oPxT/lFyi7fV1w/tW4lu8fxuwKse0SbporwmyxzYziSXXXTMPlzhju40McqXDcV4LoZXxQQ1yxGdaT4VwzLahjJ/EDdpbsv1cQvYQFdQVVA1U9Gd4104LEbhaCX1yi77687+9CLViVY149YZCaKp6M5pp5LbFjFQ+OxY+4iFsD+m3FfmFG+ZswmZjODSF5RUxNEJuod8t6Esf1jfSkWVJ8v0SfnsGz718HnOMSHpa8Xh2UvW7PaK6ZFgzFqZgrfAOKZuhvE5kBQ/EdYU1zqg7d5v/7+OlKYTnum6YDqZEtwgOAc4WFkY6Ojo6Ojo4aeQmfZwe6ZDt6VwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left [ - \\sqrt{2}, \\quad \\sqrt{2}\\right ]$$"
      ],
      "text/plain": [
       "[-√2, √2]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求解方程\n",
    "solve(x**2 - 2, x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "解微分方程:$$- y{\\left (t \\right )} + \\frac{d^{2}}{d t^{2}} y{\\left (t \\right )} = e^{t}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPwAAAAaCAYAAACTtjH4AAAABHNCSVQICAgIfAhkiAAAB39JREFUeJztnGeMFVUUx3+UNay7BA0QARExURBiQWXRD4IUhaghIqhRLDwbMVJCkSjY0ATBiBEBV9EEwYgaaaIxRiQKCohlFZFiS3h2mougsEpx/XDu+GYfc8u8N/PeLs4/mdx9c9u5p9w559yZhQQJEiRI0CAwHXiz2EQkqJcI1I3GRSAkQXSoAD4tNhEJ6iVi1Y0XgB1AmWP784Ba4Na4CDrKUQIcQHjoXV8WiZawsk9QF1HbQuy60R34BxinqR+nJh2adX8p8CtQHiUxeeA0YCpQBewEDqpyBXAncGzxSDsCjYEeCF97AG2A44tAh032HhoSb/3Q6a6HE4DDwEz1uyVwG6Lb3wE1wB5gNWLQOo86SluIXTeWA78DpZr6F9XknbPue0RNipKYHNAIeBj4G6FnDfA0MA14GfhN3f+gWARqMAjYi9BfLNhk31B560Gnux6Gq/o+6vcd6vcvwAJkk5uL8KgWWESwvKK2hdh0oxOywz9raLMF+IPg3W0L8D3QJGrCQuB5hNmbgLMD6kuBe1W7ODGZum5Y0NXb1/4h8jOUVMCYYeAi+2LyNkV+6wOz7gK8Bewio799gYEB7dsAPyh6hhjmisoWnHRjvCJovKa+M7JTv++7N0316RfQ/lH0inuDavOg+j3ARlxM8Fy2zUBzS1vdU8yGIWQU4wDwLbKTZwu2FXC65fK7vsvIuJK5IEV+BmGSPRSGtyakyH19LrrbArEH181qkuo/S1PvYguuuqTVjaa+v1er8gLNZLPUwCN99y5GYph1Ae2rgPnAMGAt8I6vbpUq16jyEuBtzbxxoS0wBTgEXIPs5CbUhB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kt8WCSXcHI8mwZZq+9yPvKFQhG57rUWuQLUSuS9kuPUgcPxx5co3FHHcsRl4GGICcD/pRpcopSGJhH7JT+TOb/ZGno455cWImcBZwC5KYWQ58gyRqTkIY2R54yTLODCR88J9HT0Diu8WIu78B2RROROLTEqBDROsoFkyyj4q3xYJJdwchoe/2gH7DkBDvMPKm2+iANmmCvU+dLcSuSz3JnAfassjHIMcIumzsSOSI5i815hRfXQtkB9PF2YXCZUi29WckEVONCPdVRIC6HAXAY8hHD0FPuQok4bQNUfRdiPLPwe7qFgIp8ju2sske8uNtMV16CNbdCvW37mOhydhDzZUB/Wy2EKsuvY7sNBWO7SciCzkn5DyjVL+eIfvVFzyO7PL5vDzT0JGr7F2Qr8HHgUcQuk6JeNyi2YKXqJsdok8z5KX/MK95liJfFLkcudRHzCQxdshN9q6ojwa/BfuRXlgU3BY6APcAzyFnjhsJ/31yL+Tlf9d/gtAFcX86hpynPqASSeb0Rb6C8q768l1/oRFW9iaUI+fn3RCDv0v93dDzHSYU3Ba8V/N2I7FVO3Pz/z10sdnkItJ0tKA3uR2xJkiQIEGCBAkSJEiQIEGCBAkSHFX4F+XXftrA8axyAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$y{\\left (t \\right )} = C_{2} e^{- t} + \\left(C_{1} + \\frac{t}{2}\\right) e^{t}$$"
      ],
      "text/plain": [
       "           -t   ⎛     t⎞  t\n",
       "y(t) = C₂⋅ℯ   + ⎜C₁ + ─⎟⋅ℯ \n",
       "                ⎝     2⎠   "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解微分方程\n",
    "y = Function('y')\n",
    "dsolve(Eq(y(t).diff(t, t) - y(t), exp(t)), y(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAAdCAYAAACKY4ZUAAAABHNCSVQICAgIfAhki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wF733EtHuuxz8kzNsK0IHP0B2LOcZCpwEdU/t7ZaOAZ5PZiBxJ4u5FHMtuoHL3GqZPepTlPG/Erzp+YKh2iQHbzaUdbyLYR3ZauHsoUf3FoE2ZPSkK0XeN0MLVpO+ZXxXHn7CqTX4+8cMfGti5i2r427P0G7H2nVvEIyWOyHvucdvKLjSIjkZdgDTc4RwkTgTeoHM1smIsod3KKOjyVuGzXgXQ/7OWpLi77jSmN0Mb5yHrFKWkqSfPDChuwT/XxxOOyXVuRFLwkWUuedLjsN6Y0Qhv9j9l4PB6Px+PxeDwej8fj8Xg8Ho+nIfkfbe9OpyL63uUAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left \\{ \\frac{3}{2} + \\frac{\\sqrt{17}}{2} : 1, \\quad - \\frac{\\sqrt{17}}{2} + \\frac{3}{2} : 1\\right \\}$$"
      ],
      "text/plain": [
       "⎧3   √17       √17   3   ⎫\n",
       "⎨─ + ───: 1, - ─── + ─: 1⎬\n",
       "⎩2    2         2    2   ⎭"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求解矩阵特征值\n",
    "Matrix([[1, 2], [2, 2]]).eigenvals()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALAAAAAgCAYAAACy0fIdAAAABHNCSVQICAgIfAhkiAAABrtJREFUeJztm3lsFkUUwH8th8UWK4eAVUkl0IBgwqEYEBoOBZFAPIhEiRiUoHihchhIiFUJYNCQcHkLaFBQEEjVcsTI6Z2gIjbxIKAiCF6oiCKIf7y3dLvdY3a/bj8I80u+fF/fvnlvdt7szJuZLVgsFoslO+TE1G8M/J5F/xZLRgwDBma7EhZLUuYBDbNdCYvFITeGbj39HEmpLhZLbOJ04J7Au2lVxGJJmxlAszr2eRXwD/AGcLyWPpbskEYsY8XzmVq4ibi8DNyZgt2RyM3fk4Lt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HpM61N97AO3AP4meD96QKkrYa4ZEVqc0uIz7jtlIt0nm9csnrI1lmFbwkhSSybaL22euS9Vf6SgY0aLEGO/sYa6j+ozrYBzWP6chL48ciIc6NhuXzgbaShTes5W331dsmeombw95PevmVYB56JHAcHca6Wv9wly0HqeyCgTJJ26qB+3IcPfVU2JqRcklg6dr2D5TjMH7ga3KCFzzfQnaq6H5Ns1GqITFc7kZHfZHFViDyxR6mec0WxEQlkY5dsKrJwdbMLmbrTIKwDVyJpRhDLkEHCe4CwXO229ciTttMotXe3SzYXGV1bhpRLEsv78X8wnlX5gLDCQVNVBbJa/z7C+S3AI8iNbUYWcF52AYtCbBwBXgVuR5L+wxE+QWaHnsg2TxugzEdnBpKvOeQg+eJXVM/t9iBTXg7SYCXI3qjflFxGdP7YF9gQoeNHCVBMzX1Xh1nIYrA30t5uViCL7YHIOykOSdoJpNMco3pefQ3yOu2PIfeQJJbO4cSnHrkzGHYEviC6L9agiYFOGdGnJxsM7PRS3VID3VykA4b59GvktnptqUc+UOUtkE68BlgV4Ls5srke9jkzov5BI/BEJE/14wnkni4KuN4QWdx94JIlbadCpOO52+BS1Td5UShOLAE+QR4Wb7sNR3Luv4AJhrayRg4ywqT5T54j8A9CJ5V3BR5Fpr8033sO6sBbkJdevMwhvPM6TFbbXTKqnbxi6l0nTFfZhQbl6yKWpyWr8D9Pd1bBFcgLSMUp+C5Qv86W1wT93Vqvn4Psd3rzywXIHnA/ZFvS+fhtbeYh21HlGdSzEbJXvdwjr0RGSksdk4uMquVIx9kUoHcI2fsuTqkeffCfwhfp9Vvx/3etoKm/LMBPKZKjJ32hvYPaLk5Y3lLLtEdW4N8hx6YmeX02WI2c+1sspySTgAuyXQmLxWKxWCwWi8Vy8vM/N7QDmhHvA6MAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{\\sqrt{2} \\sqrt{z} j_{\\nu - \\frac{1}{2}}\\left(z\\right)}{\\sqrt{\\pi}}$$"
      ],
      "text/plain": [
       "√2⋅√z⋅jn(ν - 1/2, z)\n",
       "────────────────────\n",
       "         √π         "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 依照球面贝塞尔函数的形式，重写贝塞尔函数\n",
    "besselj(nu, z).rewrite(jn)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "用$LATEX$输出$\\int_{0}^{\\pi} \\cos^{2}{\\left (x \\right )}\\, dx$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\\\int_{0}^{\\\\pi} \\\\cos^{2}{\\\\left (x \\\\right )}\\\\, dx'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "latex(Integral(cos(x)**2, (x, 0, pi)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.4 为什么选择SymPy？\n",
    "除此之外，还有许多计算机代数系统。 是什么让SymPy成为比其他选择更好的选择？\n",
    "\n",
    "首先，SymPy是完全免费的。它是开源的，并且在BSD许可下获得许可，因此您可以修改源代码，甚至可以根据需要进行销售。这与像Maple或Mathematica这样的流行商业系统形成了鲜明的对比，因为后者需要花费数百美元的商业许可证。\n",
    "\n",
    "其次，SymPy使用Python。大多数计算机代数系统都发明了自己的语言。不像SymPy完全用Python编写，完全用Python执行。这意味着如果您已经了解Python，那么开始使用SymPy要容易得多，因为您已经知道了语法（如果您不了解Python，那么它很容易学习）。我们已经知道Python是一种精心设计，经过实战考验的语言。SymPy开发人员对编写数学软件的能力充满信心，但编程语言设计则完全不同。通过重用现有语言，我们能够专注于那些重要的事情：数学。\n",
    "\n",
    "其他CAS，比如，Sage也使用Python作为其语言。但Sage很大，下载超过1 GB。SymPy的一个优点是它很轻巧。不仅如此，它除了Python之外没有依赖性，因此它几乎可以在任何地方使用。此外，Sage的目标和SymPy的目标是不同的。Sage旨在成为一个全功能的数学系统，旨在通过将所有主要的开源数学系统合二为一来实现这一目标。当您在Sage中调用某些函数时，例如integrate，它会调用其中包含的一个开源软件包。事实上，SymPy包含在Sage中。另一方面，SymPy旨在成为一个独立的系统，所有功能都在SymPy中实现。\n",
    "\n",
    "SymPy的最后一个重要特性是它可以用作库。许多计算机代数系统（CAS）专注于在交互式环境中使用，如果您希望自动化或扩展它们，则很难做到。使用SymPy，您可以在交互式Python环境中轻松使用它，或者在您自己的Python应用程序中导入它。SymPy还提供API，以便使用您自己的自定义函数轻松扩展它。\n",
    "# 3 注意事项\n",
    "首先，我们应该清楚地了解SymPy。SymPy只不过是一个Python库，像NumPy，Django或者Python标准库模块sys或re。这意味着SymPy不会向Python语言添加任何内容。Python语言中固有的限制也是SymPy中固有的。这也意味着SymPy尽可能尝试使用Python习语，使得熟悉Python编程的人可以轻松地使用SymPy进行编程。\n",
    "## 3.1 符号\n",
    "在Python中，变量在定义之前没有任何意义。SymPy也不例外。与您可能使用的许多符号操作系统不同，在SymPy中，变量不是自动定义的。要定义变量，我们必须使用symbols。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAASCAYAAAAZk42HAAAABHNCSVQICAgIfAhkiAAAAW9JREFUSInt1j9IHEEUx/GPJqSwskxhGSE2aiskcIJa2EQkjYWwoIWFVUgVCNhpIwgWgpWilVimkDQpQiBFCi38A2muCCSQgKiglX+KGXE5ONmbI3vNfWHY3bfz3vzezJvZpU0pvMUqvuIct9huqaJE9gXxFzjW4kSyKKCS4DuMXnRE/7qJdNY8f46dJ2vsHdiI75YSBKXyBT/juA0xgGsc4UnOvhyDrSeIyaSvSJ6KBlbkAFvow3S0fcA77GCuSTGl0oMrVDEvzMIeniXGy5SwIvVYjE63+Iaugn7VnF+RttGApopHEnlax+lv7n4GlwUHW0F3jW0Qb7ApJJpnv2DcJKZwg9/CDKw1GS/Tgs0+LszcIfpxglm8bFLEfyefyCvs4hfGhPL6KJRfmd+OJO73yAA+4QyjQlkREvsh1Phr4Z+nTCZig+fxOuThkPiH9/edX+APToVyqmVEqM3viWIy6XtkweOnXjVRU5s2RbkDD0pkdkQOpkQAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x + 1$$"
      ],
      "text/plain": [
       "x + 1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=symbols('x')\n",
    "x+1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "symbols获取由空格或逗号分隔的一串变量名，并从中创建符号。然后我们可以将它们分配给变量名称。现在，让我们只定义最常用的变量名，x，y，和 z，以便本节的其余部分使用。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "x,y,z=symbols('x,y,z')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Symbol的名称和它所分配的变量的名称不需要彼此有任何关系。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "a,b=symbols('b a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAATCAYAAACgADyUAAAABHNCSVQICAgIfAhkiAAAAPpJREFUOI3V0rtKQ0EQxvGfmiiohdipRV7A4K2wtRHS6iPYCFbWPoZlwMbGygtYGcHOQvFSphAk9rFRRBRFi7MH4rInErBxYBmYmT/zzczyh7aBL6x1K+pPxOaDv+614y1eUeoFGsI7Ln4rjKVWUZbJnMU+HvGCBqaLwIXgKziXLWkHN1jGGcZSCuqhuI25KLcbclsp8ErxKRZDbi9OlPGGlvRGKwE85OeMVQziGB8FIDzEYH74VgKCleAbMZhvdDwBTWAddznYaZeyGe4x0hEfxSk+UcuDfcGX8IwmhjGAI9lPWsUkNrEdd5sJ3eqYwgGewjvBUkL+f7FvAyYxszVLv64AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$b$$"
      ],
      "text/plain": [
       "b"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAABHNCSVQICAgIfAhkiAAAANhJREFUKJHN0TFKQ0EYBOAPopBCQQkSLVJ4AcHulV4jFoJ1zpDG0jvYKAHBC6ggVkpIiJBOU5ouEVNYKISgxdvg8rJNwMIftpnZ+Wdmlz+aQ7QwwAcm6OJ4fqFUEKyjjU/0cI9XZKjjCw9FlzVsJ9x3guvzsrFfMEoRm2iGiBPM8B2dJ1iJBHu4RRUdXOIdU+ziCP2iS19e9CCR4CQ4NWKwFsDrhGADw8BnMbEVwAFWI7yCm8BNUS5uvPNb9hQXeMOV/EEW+szdzjGW/8mjvPx+WHaWEv3D+QGVVDVPL1hNBgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$a$$"
      ],
      "text/plain": [
       "a"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通常，最佳做法是将Symbols分配给同名的Python变量。最后，让我们确保理解SymPy符号和Python变量之间的区别。考虑以下：\n",
    "```python\n",
    "x = symbols('x')\n",
    "expr = x + 1\n",
    "x = 2\n",
    "print(expr)\n",
    "```\n",
    "你认为这段代码的输出是什么？如果你认为3，那你错了。让我们看看到底发生了什么"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x + 1\n"
     ]
    }
   ],
   "source": [
    "x = symbols('x')\n",
    "expr = x + 1\n",
    "x = 2\n",
    "print(expr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "改变x等于2，没有影响expr。这是因为$x=2$代码，改变python变量x为2，但是并没有影响expr中的SymPy符号x。当我们创建expr时，python变量x还是一个符号，而创建expr之后，我们才把python变量x赋值为2。但是expr仍然保持不变。这不是SymPy独有的。所有Python程序都以这种方式工作：如果更改了变量，则使用该变量创建的表达式不会自动更改。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcdef'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x='abc'\n",
    "expr=x+'def'\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'abcdef'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=\"ABC\"\n",
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "要更改表达式中符号的值，使用 subs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAWCAYAAACCAs+RAAAABHNCSVQICAgIfAhkiAAAAZpJREFUWIXt1r9LlVEcx/FX1pQNuUWUm+RYYGhDoERzDbrc6U5OLWGgQ4h/QQTaEA0VODU0OAuSKYJCSQQOLXcOScohQvoxnCMdH73mPRefW3TfcDj3POd8z/P58Jzv9x7alMIwpvEaX/ATsy1VlMm6IH4bG1pspBoFDGbEDqEHJ2J8XSMdye+xuHCszqaX8A2LGYJyWcAHQdehpEaWYj9QZ+00TuJOU9KOidTIG3xF/wHrRnATj/CuBF0NkxrZwRou4nzyvBMP8BGT5UlrjI7CeDn26fGaxAWM4/Mf9qsJ5zltT+PcwgFzz/Jk7+dUYbxrpB8v0Yu7WMHzI+z3EGcLzy7jVoyvFebWG9DaEF34gVdxPI/vuNLEnlX55Tdl0BHLL2wJfzx9qOAGHuNtkyKOnaIRQhk+LRjYxP1SFWVSzBFCnozijJAfn0pVtJfbscG52F/zu0hs4l694OvCWVwVrgbNUpWfI1P2V7q01Q4LnhMS/GrGi/8aKoLTmVYLyaEbE3giXArfC8n+zzEqfIUtvLD3etKmzf/OL/5RXEVIeEfMAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$y + 1$$"
      ],
      "text/plain": [
       "y + 1"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = symbols('x')\n",
    "expr = x + 1\n",
    "expr.subs(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAOlJREFUOI3N0r1KQ0EQBeDPkEJQEIyg2AipLARBUlgINhY2Fj6Eb2CvjUWw1ldJEdIIVkIiIoJFqoCIf2AliiEWu4vhcpV7wcKBZYbZOcw5h+GPookOBnjDC3o4QG18cCID/EAXN3jAFNbRwF2sB3kbJ39gcoQRTstKWI3AdmpUCgJ3Yr5KjazGFPuYxoygbyOCtvD424b7SC29FuYLsiMO7+JWcHWtDBiW8I7rskDCIYwwR3FXYTHmYfZjGQs5gIrvAzhPzerYwDaOcYY+ngVzNlEXnN7Lo7KCE1ziCZ94xQUOMVtQ0n+LLxK6LQuL4DX5AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$3$$"
      ],
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(x, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.2 等号\n",
    "等式的符号表达:$x+1=4$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAASCAYAAADfVhk+AAAABHNCSVQICAgIfAhkiAAAAihJREFUWIXt2E+ITWEYx/HPMFlYaJYU2UjZ+LdQirrExoY0G2VyxYKSLlFS6iZFspjJRklmYjaysLCQDQ1iYXEt5F9pskHIv5DCWLzn5nbmzJ1z7tx/k/utU+c+7/M+7+8+5z3P+3To8F/Ti7O4gy8Yw+WWKkqmT9A2ht0t1pKJkiD6K55ozwQvwCdB47gEz2iCgHy0cK6GuQewGHOwt36S6kYXLuIDziU5xBN8U0jG1oRAg9HYqbpKrM4tvIjWbUf2Yz124luSQzzBh/EHJzCzwn4GO3AeR+ouc3qyRNhsAxiZyKk79vsRLgnJ7BN27VEcxBXsaYDQRlNATwb/Eq5N4tMt5OmVkJ9MzMcPjGKf8HrewKysgSLyaq/BleTUdsiN+nfCp7kGU8Q8jt9YXWErytBFnKxY8B5mp5mkMX+mTE57dBGr8AunY/aihATHS0SZdxX3u/A95eL9xr+Oy7EZQ8IDqKSUMm67UC4Nz3EszYSuBNs2DOMt5grtx1RapLzQyqzD7SnEyQldxTC2Z5hXzxrcg48p4wygEN/Bm4Sd9lhoP0aELT+ApxlEthMFLMzgP2TiBP/EhQnGVmIF7uIZ7scd1gil4CXmRbZeoa5MdqpWI6+1h1yzKKpSg5fhOj5jI15H9qt4KNTQtcI3gWayJboI5Ypwcg9G9+9xqMmaMrMIb4TasjRhfIPwZB7UGD+v9h1cVL0LGa1RUyMomoYfezp06NBS/gJPGpj3SZRgYQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x + 1 = 4$$"
      ],
      "text/plain": [
       "x + 1 = 4"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Eq(x+1,4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一下都是错误的等式符号表达式\n",
    "```python \n",
    "x+1==4\n",
    "x+1=4\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设我们想知道是否$\\left(x + 1\\right)^{2}=x^{2} + 2 x + 1$。我们可能会尝试这样的事情："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x + 1)**2 == x**2 + 2*x + 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "==代表了精确的结构相等性测试。这里的“精确”意味着只有两个表达式,在结构上完全相等才会相等。这里，$\\left(x + 1\\right)^{2}$和$x^{2} + 2 x + 1$形式上是不一样的。实际中，当使用SymPy作为库时，测试精确的结构相等性比它代表符号相等或者测试数学相等性更有用。但是，有的时候，尤其是在数学中，您可能会更关心后两者。我们已经看到了等式符号表达方式$Eq$。为了验证两个符号表达式是否相等，基于基本事实$a=b$， 可以得出$a−b=0$。因此，检查$a=b$，可以通过$a−b$的形式简化它，并查看结果是否为0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAM5JREFUOI3N0rEyQ0EUxvEfJcMVWhoZ8Qpq75PnoDJ0Kl5BK0U67yAUiUYmpZGYoRDNuePOkXszYxS+5ps95/x3Z3c//lC7uMIz3jHCOVpNUBsTzHGDU/RjfY+dOvA2hrqpfhb1y0XQfjSHWE29DUwxw7o0cBzew2cCX3GHNRxl8DD8oeYaj+GdDBbhLzVgWd/K4DKthM8zWO5YWKzN6lwVHIR3asCD8B9v0Lb8O97Ed2T9KgDlqdXInfiO3EBD5GAP1xjjA0+4wHYT9I/1BRgnMa7SDNsAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=(x+1)**2\n",
    "b=x**2+2*x+1\n",
    "simplify(a-b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABsAAAASCAYAAACq26WdAAAABHNCSVQICAgIfAhkiAAAAU1JREFUOI3t0ztIXUEQBuDvRgmYKq1gqtzGQi6mCAja2AQsQ5oUAcWUkl4hcLFRFFGwMNgYSJXOMo9OtEpq0UDEziIIFj4aX8WZ4OFwz57gRbDID8vuzszOP48d7hHe4CrW23adPUjonmAZx+2SVJHVsIZDfLhrsncYxhhOEu+/yUr8siCv4WPoZlMB9OIMi3FvKu9ZAxfYRkdOvhBvVlNEnfiJXXT9A5lcBqNxn4r7Z+k/YToiHcjJqsh6ZJXYx0TYfsHDFNFznGOuIK8igxk3I7KFR62M/qbZiU/4hfepiErwJ3cex2nK+HEusqq1VHj7Gpc4CP1KGUkt9i7ZALfCM/RjU/ZxvsuaDyNYD/kwNlBHH3ZS2ZWhqXXPBmXl2kN3yF6F7fptiMrIGjiSle5pwf5H2A8VHSXnoAR1fA2HL/C7oJ+Mff4Wvv+jGtdLEFW+iDzrNQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$4 x$$"
      ],
      "text/plain": [
       "4⋅x"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c=x**2-2*x+1\n",
    "simplify(a-c)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "还有一种方法称为$equals$,可以测试两个表达式是否相等。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.equals(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.equals(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.3 ^和/\n",
    "SymPy遵循Python的惯例：^表示逻辑异或，使用\\*\\*取幂。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True ^ False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True ^ True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "无论何时组合SymPy对象和SymPy对象，或者SymPy对象和Python对象，都会得到一个SymPy对象，但是无论何时组合两个Python对象，SymPy都不会发挥作用，因此您将获得一个Python对象。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sympy.core.numbers.Integer"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(Integer(1) + 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(1 + 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在SymPy中，两个Integers的除法给出了一个Rational对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACEAAAAUCAYAAAADU1RxAAAABHNCSVQICAgIfAhkiAAAAadJREFUSInt1cGLT1EUB/CPGWkWamqISUmmphSlxELJ/GYjJcU0/wJ/gOzZ0MiOWBoLO0VWs5hYUJOaBUlmpWaapkb9EJLIYHHu0/Pze2/uz28Wkm/d7nvnnfO933PvOffxF2IcV/EI7/EdtzLitmIFV0q2S7iPRXzCGzzBOWyqI3uaFv6AuQ5EnE6+oyXbFzzGDUyI5GaT3xK2V5GNYhjr0OhAxBSa6C3Z+ip8LyTe6xm82SL68RmTOaTYm3inC0NPZmAdjmED7mT6H0/zs8Kwfg1EnMRHpcxacBYbxY7tx6EkYCKHvGH14+gTRXy7xmc58RRjSnTTT3R7HEdElndrfAZFoQ9iDEOiVfflLNCw+k5MiqLszyFM2JFinheGbnaiVxTZA7zrIG4BL7Abm7sVcVjcfHVHUYVtaV7pVsQYvuFem2+7RA20okdcVlswg7f83qIn0lAiOYib6bkpWq7wncGrNosdxWU8xEu8Fh0xIgpzGafa58Z5v7ZT65hPfgfS+5kKnj24Jv5FTXwVdTOb1hioEtAJLiYRO9eC7E8xJ7L8j38PPwBKMGKsnJFK6gAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\frac{1}{3}$$"
      ],
      "text/plain": [
       "1/3"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integer(1)/Integer(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sympy.core.numbers.Rational"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(Integer(1)/Integer(3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在Python中/代表整数除法或浮点除法，这取决于你是在Python 2还是Python 3中，并且取决于你是否运行：\n",
    "```python\n",
    "from __future__ import division\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACEAAAASCAYAAADVCrdsAAAABHNCSVQICAgIfAhkiAAAAZhJREFUSInt1c+LjlEUB/APDRYarx81WWDevJGS7DSlTFHY2mvWZiGL2VmNlaRESWxY2liMxSTEQvEHSDIUjw2GlMlvYiye8+Rxe+94Hyxm4Vu30z33e879nnvveR7mKdbgPJ7hMwqcxIqGeQrMZsaLOrEvCezgDgZwGQ+wDYewF9vxuoGQmSggxbu5gq6G0oOJ/0T4zzYQUMRohPWx0RMsTNb6lerfY+m/FlG/jp1hr+F7wnuL29iNIdzoUcgS7Mc6ZQF3cQvfcgHHlScxllk/HeujPQoodH+UjzFcJ9aPvRV2JpO08i/vUcQF7MJq5RVuwTm0cQVbK2LaHXNhQdjZHvlHkvk9HFC+rTGMYx+/nkRVaUt3LEt4f4qqw3ZUjrqIqbAbM8Ebwj78SxEvw3btso7ft+iHXHAD7Il97ucITT9WHWzCosS/GSu75B/Eo8h1OCeig+kgTeAobsZ8CqsSfhFr7cQ/jk/KLjiDY7iEj8GfxOKcCFirbK/n+IKnOJWpLCdiGBeV/543+IpXuI4RPzvtP+YffgAkOGoQ2hrWHQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$0.5$$"
      ],
      "text/plain": [
       "0.5"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from __future__ import division\n",
    "1/2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "为了避免这种情况，我们可以明确地构造理性对象。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEYAAAAUCAYAAAAwaEt4AAAABHNCSVQICAgIfAhkiAAAAm9JREFUWIXt102ITlEcBvDfGEk25GsoG0VZYWOhqBkfKfJtw8Zbo0mRJCKlJBkLCx8LSmkUCxEKkQVqkMWUqSmzIE0WPjL5jjIYi3OmebvmnTnva7wzap663XvOff7P+d/nnvO/5zKE/xLrcAKN+IROnEuMrcJPHI/tcdiEK3iGb/iI+6jFsH7LugxoFsz4jFbFGVMX+TWxvTm2X+I86nEGH2L/JVT0V+IpyMWBq0uIrcF0IeFqxRlzE+2ojO0FWO7PmTEJL6L22q7OLOl2JKzJ9FegId47nJhYf+AunsZxi8FowYhrwnKCO7H9K8N9jVPxurqrM2vMrhh4ULfTcAQbcRp7ikxyILAMI3A5kd8Rzz96IzUIbygX23tj+4LSClRO6UspH9XSl9JFfMHIBO5wtETtJb0RpwgVuw1bY8At4Q2UgpzyGjNSKNYXE3WPRN0bKeT6SO7EA4xKHKQtLy7laEjUJd2YFZG3IUFzW+S2Ymz+jeEFAt7mXdfia8IgcBRjMn2zsRJnBePy0ZyoWwxW47u+Z8AWHMMTLMS7voTXCwX4leDmyb9Ks7xLqVL4RN/sQ2t71GrBxJTBlwput2CCMMU6MCMluAByymdMTeTU9cLZHTmPMT5l4HnCknmOybFvXRS5miJQADnlM+aEsG+pKnB/X9RokqkpWXTVmFm4Lvw7LBaWEWGb3CTUiPnCP0s5sSoehB0qzNVdtNuxM8N/iDc9aG3EAcG4RqHwZtGWp22asPt7j5k9kBcJLj/q4yEKIaf0GbNf71+1tjzunNi3o0StTtwrIcdBj0PCw00d6EQGG1r9m8//EIYwhNLxG0xvuoSN7/dAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x + \\frac{1}{2}$$"
      ],
      "text/plain": [
       "x + 1/2"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x + Rational(1, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4 基本操作\n",
    "在这里，我们讨论SymPy中表达式操作所需的一些最基本的操作。稍后将在高级表达式操作部分中讨论一些更高级的操作。\n",
    "## 4.1 替换\n",
    "您可能想要用数学表达式做的最常见的事情之一是替换。替换将表达式中的所有实例替换为其他内容。它是使用该subs方法完成的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAASCAYAAAAZk42HAAAABHNCSVQICAgIfAhkiAAAAW9JREFUSInt1j9IHEEUx/GPJqSwskxhGSE2aiskcIJa2EQkjYWwoIWFVUgVCNhpIwgWgpWilVimkDQpQiBFCi38A2muCCSQgKiglX+KGXE5ONmbI3vNfWHY3bfz3vzezJvZpU0pvMUqvuIct9huqaJE9gXxFzjW4kSyKKCS4DuMXnRE/7qJdNY8f46dJ2vsHdiI75YSBKXyBT/juA0xgGsc4UnOvhyDrSeIyaSvSJ6KBlbkAFvow3S0fcA77GCuSTGl0oMrVDEvzMIeniXGy5SwIvVYjE63+Iaugn7VnF+RttGApopHEnlax+lv7n4GlwUHW0F3jW0Qb7ApJJpnv2DcJKZwg9/CDKw1GS/Tgs0+LszcIfpxglm8bFLEfyefyCvs4hfGhPL6KJRfmd+OJO73yAA+4QyjQlkREvsh1Phr4Z+nTCZig+fxOuThkPiH9/edX+APToVyqmVEqM3viWIy6XtkweOnXjVRU5s2RbkDD0pkdkQOpkQAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x + 1$$"
      ],
      "text/plain": [
       "x + 1"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "替换通常是出于以下两个原因之一：\n",
    "1. 在某一点评估表达式。例如，如果我们的表达式是$cos(x) + 1$， 并且我们想要在$x=0$点计算表达式的值，那么我们得到$cos(0) + 1$，即2。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAMJJREFUKJHF0j9LQlEYB+DH6BNYhJ/HxcmpD9CgQxCImxAIbi5u7eLSJji5NzQGDRItDtHQ3J0aSnS4LxJytBMN/eBw4XCe+77nD3/MCdqYYYkPFLhHC0cpdIk13nCLIcZ4j/kpKruojmbijzW8Bjz/TevXgW7s6zORz/h+5VY5xiIqNXLRKMA8F3QCPKOaA64CPClP8Md0AyxwlgN6AR5xmgP6AR4c2MP3Z3GBCVbKSywS619izTaDqHJo3OW0+8/ZALBUMPfsVQVVAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$2$$"
      ],
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = cos(x) + 1\n",
    "expr.subs(x,0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 用另一个子表达式替换子表达式。我们可能希望这样做有两个原因。第一个是如果我们试图构建一个具有一些对称性的表达式，例如$x^{x^{x^x}}$。为了构建这个，我们一开始的表达式为$x^y$,接着我们用$x^y$替换$y$。然后我们会得到$x^{x^y}$。我们再用$x^y$替换$y$，我们会得到$x^{x^{x^x}}$的表达式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAUCAYAAACXtf2DAAAABHNCSVQICAgIfAhkiAAAAS9JREFUOI3t0r8rxVEYx/EX4pYNScrGIAqzKIMMMmEx8QcYZJJ/gEUGpEw2yWL0YzCpW0aFARkUEzKQn9fwPbdut6/bvdctBp/t+TzPeX/OeTr8cV1jOsvrwgvaShGwhY0s7wDLpYAT3f48ox7BHepKFdCNFGqRwAWmch3YCweGs/wyrIfefIafEO17ADM4Q2WugE584AQVGf5CgK/FnEliCY8YygVPK33TiVDPhnoT5THzi/jEbj5waMIzrjAZ4Duo+mZ+HO9ozzcA5gI4hUNU55jdx0ohcKLvlw5ojemXo0G0vhvUFAIfE+30JgSsxsz0hZlT0VfNW4N4xTHqA+BN/CsKVg+ecInG4I2KXrH9U3gnHkRrac7qHYWQ3mLhLbjFPTpi+v0hIFlswL9+V1//kUPNDQ0UswAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x^{y}$$"
      ],
      "text/plain": [
       " y\n",
       "x "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=x**y\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB8AAAAYCAYAAAACqyaBAAAABHNCSVQICAgIfAhkiAAAAXtJREFUSInt1bFLVlEYx/HPq+ngGDQEhYMNDqIYjrVIiOgQiBJOSq1FS0PoH1CLgziIBaKjTm5F0mYh5CYoIkgQpRJRBBVqpcM5V64vOsh9j4v+pvv8Hu7zfc655zyXtGrF21zcjenEzENdwheUUI0lXM8nU+ovNtCAdszjU5asTgyHJtThMe5jp1KF+2Kx+pw3inVcifE9fMOjSkEzlYTv+DLGT7AtbHOm1thMTaXh0IE9PMVPtJXlJ3E3BTjTe+Fwdea8BqxhLCW4Hb/wHzeLFHqDffSU+SVMxdzznN+CHxjAHF4VgbfgH1YcvYYjEfwi59XjM4Zj3Cys/naRBqYiaDDGQzGeQVX0LmMVE2XvzmKhCPwa/uAjHkbwa9QWKXoaPYvQfbwTJlTFVXWC/zX3/AC/U8CPU79wcDaFlY+fFbgLu1gWZvOqML0aU4NvCdu7gavR6xVWP5cSnA2LTUd/CvAhNlDo/p6kG9jCd2FQlOtOhC+mgF/ofOkAf4BPeN7looEAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x^{x^{y}}$$"
      ],
      "text/plain": [
       " ⎛ y⎞\n",
       " ⎝x ⎠\n",
       "x    "
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=expr.subs(y,x**y)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACMAAAAaCAYAAAA9rOU8AAAABHNCSVQICAgIfAhkiAAAAY5JREFUSInt1T9IlVEYx/HP1VIMWoRA0RD6A04VYdCQCCEibkUOTQWtjg6hW0E25NCSZA7SlhCIixIODiqBNYSQg6AuYeGgCCWWpsM5l14vV1re+0Zwf9Pz732fL8/hPIey1GEIF/ECuawaz+F6tIfRG+0neI3qfOGJDGAeow/TOIlnOI2z+IndDBiO6CNmUCUMYASNeISrWYJcwyomSt2oWxhzUyL2HMs4gwZ8wjks4EopYXL4gFfR78U3nEcN5tEWc7fwtpQw0IFfeIhttJS64d80jz10pvnTdzjA7YJ4DqMx97QgdxPf8VvKN+My9vEZlYn4YAQZLlK/hXsYx2SaMPyZwP3o90X/DSoSdU34gv7oXxKm05omTCN2sIaeCDIlLKy8arGElwXfjmE2TRgYiBAHwttyKu0GxVRxTHwjYT/AjwxYiuqucPbrwmSG/hVIl/CSLgrrfElYaM1Zg9wQjmMF9TF2R5jOeJYg+X2xLrwrSS1EoFSv7HG6gK/YFHZFodojzPssYMoq67/VIVQrUpM+oqGQAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{x^{x^{x}}}$$"
      ],
      "text/plain": [
       " ⎛ ⎛ x⎞⎞\n",
       " ⎜ ⎝x ⎠⎟\n",
       " ⎝x    ⎠\n",
       "x       "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=expr.subs(y,x**x)\n",
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "第二个是如果我们想要执行非常有控制的简化，或者可能是SymPy无法做到的简化。例如，说我们有$sin(2x)+cos(2x) $，我们想要更换$sin(2x)$为$2sin(x)cos(x)$。正如我们稍后将要介绍的那样，expand_trig可以实现该功能。但是，这个功能也会扩展$cos(2x)$，这是我们不想要的结果，一种简单的方法就是更换$sin(2x)$为$2sin(x)cos(x)$。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARQAAAAYCAYAAAA7xQK2AAAABHNCSVQICAgIfAhkiAAABqxJREFUeJztm2uIVVUUgD8flWahPYwKiwupmD0sCsEecNPAkh5SIvmrG6aIVpRQoRHNn7RMs5IyymKKoizDQIoSwjENTMcUrPyTNgp60ymzpCZz7PZjrcNsz93nnn3uPefMmZnzwWVm1t577b32WrP245wLOTk5OTk5OamzANgG/Am0A+uAK7t1RDk5OT2WL4EHkCRyFbAW+AU4tzsH1RcpABWgOUad7wKHgSEN6LgOGdfMWEaUPH3R5ixzFnASuDOgvE/76zzgQSTr/gR0AH8AmxFj+jegu0C8CeV64D9gfgy61gJlJDiyTG+xOck4S5uLk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LwKVaz7PXdf7StNnGS5yaCAGuAe5G7rvafGU7Q/T5CYszSNYXccWxR3f7aw9yB+nKwQh168ab1F3Yz5Z+hgFTkO3mSeA3X7sCtZ/y2GjRcpOLVbY5ZDwzkMd2Za2/MqR+f62/x5DVsypeFlBu26GY1Jq/NG12pUQ8Rx7XOEvLF2Fx7EIW/RUnRSLubJ7UBjuovpRy4S1tb75LUCCehNIPeSLUXlW7iynAv0iQDke20SeoHYyXa1+fGLIo5/ZVWtf2evRI7HcoQfjnL02bXSnReEKJEmfd4QtbHLuQRX/FSZEICeVprdxK+BeebsN+ZPJu0m83ZAXiSSggb1IGnZFvQraNe+l6K3cate9qQL7wVUEuxzzMJwu2R4Tmk4UbtP3PnHr+HqD9VoCnfO2jzF9aNrtSorGEEiXOIFlfRPGDK1nzV5wUcUwo92vFTuRyqsnyKRn1jyI3zmuQG/plyCMtL1DMZ/0F4ksoM1Q+zycfp2MqU73d9bbMNwf09QFi9yU++SxkRTsOfAQ8C7yO2LfBV/d57eMQ8CqwhK7HoJuovr2PMn9p2uxCifoTStQ480jKF1H84ErW/NUoU5H/02bkSVQFOXp5Muu7MU2E3wi3GPXnIF9a2otk3CPI9vUJ4Gyf7gLxJZTTkQD41pCNVNnvwNWWNt5LQVssZUORi66g1WECss08jGxTDyKTOs1S9z7k7HwMuRj7AVkNbRd0UeYvbZvDKFF/QmkiWpyZJOGLKH5wJWv+apQmavurrZvGFRsLEEOujUHXw9ReGbJCX7S5J5P7qwcxCLmtX9egnsHIKrem4RElT1+0uSfTJ/2V1W/XhtEJfId80asVubCrh1HImXwJwe/DZIW+aHNPJvdXTk5OTk5OTk5OTk5O7+J/qex8PldWMyAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$2 \\sin{\\left (x \\right )} \\cos{\\left (x \\right )} + 2 \\cos^{2}{\\left (x \\right )} - 1$$"
      ],
      "text/plain": [
       "                       2       \n",
       "2⋅sin(x)⋅cos(x) + 2⋅cos (x) - 1"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=sin(2*x)+cos(2*x)\n",
    "expand_trig(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOUAAAAVCAYAAAC5WykPAAAABHNCSVQICAgIfAhkiAAABfNJREFUeJztm3+IVFUUxz+rm7lZaD+MCosHbYsZZFEIRkFlYEm/KJH8qwlTRC1KqNCI/Cct0ywkjLLYgqitDQUpYiFcawPT3RK28p/aVkGn3LKNqG1zbfvjnGnuvrl33n0z7z2XZr4w7My555x7z/e+c9+5972FOuqooyYRAKNAa4I+3wKOAVOq8HENMq4liYwofdRizFkgCV7jwmsezgUeBHYA3wFDwG9AlxpOqGIAAckm5bXAP8DqBHztAPLAmQn4ShO1GHMWsPGaZi6YiJyH5UjiHAXeBjYAbwCDKm8HGirs/DRgJnBhhfZhdOi4mhLwNQeJb20CvtJELcacBWy8ppkLJiLn4WbgDkpXgQuAw2p8bwIDqRYtyMr2aoI+DwKHgIkJ+kwS4y3mHHI93JjgeE4FXLxmmQsVz8NaHcjWkPxO4BPkFjyMrCx7gBUhvYDS8tWUBcC7wM/AX0A3cLtjLM+q3TxHe4e23xOSN2hfo+rDxNMqn2/xNwdoA44gMea1j0UW3UXAp0ipMwT0AmuA0x1j9eUv65ijkKP6pEyLV19OIZpXG1y5ABnPw2NquMWQLVNZHllp1gPbgX3A/pB9gDspdyOb7L3q/00kMU8CN1nG0g2M4N6Uz1bbbxm7+mzW/mx3m1u0bVNIvlT7GgbepxjjAaAzpLtefQwA24Dnga9V1omU8Cbi8JdlzD7IUV1SpsVrHE4hmlcbbLlQQGbz0IisTOFs7kFIPd9ic17od4A7KUeR1cLEfJV/FJJPQUjsjRhzq9rn9HdhdWvDvkmfqu37DNks4ARwHLjCYjPD+D5X7Q8jJU4BjcAu7PsGX/6yjNkXOSpPyjR5jXNN+vJqwp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y8rarSj9NyArdXvWI0kctxpwFkuI1LpzzMF7/KyIKI8CXyAvJ3cjBQSW4DNnXbMT9vHS8oBZjzgJJ8RoX9Xmoo4466qijjorwL+5jKzHB1MaIAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$2 \\sin{\\left (x \\right )} \\cos{\\left (x \\right )} + \\cos{\\left (2 x \\right )}$$"
      ],
      "text/plain": [
       "2⋅sin(x)⋅cos(x) + cos(2⋅x)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(sin(2*x),2*sin(x)*cos(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "关于subs有两点需要注意。首先，SymPy表达式是不可变的。没有任何功能可以就地改变它们。所有函数都将返回新的表达式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=cos(x)\n",
    "expr.subs(x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD4AAAAVCAYAAAAeql2xAAAABHNCSVQICAgIfAhkiAAAAzhJREFUWIXt10+IllUUBvDfOGWahQYZFVaLpqEMsiiEonYuykVEheQm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"text/latex": [
       "$$\\cos{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "cos(x)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "另外一点是，要一次执行多个替换，请将对列表传递给。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHoAAAAaCAYAAAB4rUi+AAAABHNCSVQICAgIfAhkiAAAA5BJREFUaIHt2H3I3lMcx/HXvd2TmdoofxCShikzCousJJL5Y6VJU/QTTSLR/IFSF8W9kUytyUO57mjlIUn+0Bo1646WtDxG6MYfDG2Yhzbz8Mc5l/u6f/f18Hu6XHf83nW6r3N+53t+n+99zvl+f+dQU5OBm/AuforlTVw2VEU1A2EVVuIknIz78DtOH6aomn+HPbhh2CJqBsdcrMEBLB2yFrgaf8Vy/ZC1/CdYip9xEHuFUD5sjsMP2Kee6Mo4BItxFsbwPU4rME4iTMoFJfWMYBs+w4Nm90QnqvG5L3NS9a3xxZen2kfQjM/Wp54dwKd4G3diF26tWmgObsGFuBa/9OiXx9d1sb6uy1inYD/eKKS4OBOm0lOnsr2b4TL8gQ+FnNvioWj4eIaXv45nCohOlF/dp+I3PBzrDd13dB5fl8e257u8d6uQuvKeNhLlfL5d8DFdvojjNnoZN2OnJNbvivVnzYwA67ECJwi5egx/4tICohPlnB4VosrHmB/bGnqH7qZsvs7Dr/iywxhXRJtHCmhOVB+6W+nqKTPnaxrHCrtiEjdHo1eFXJymKaye/fhWyI2XFBSYKOf0vcIOPbetraH3ROfxdXt8fkxb2wJ8hd1YWEBzorqJHsHmON6mWO/LmKk4P4HDKhDSzqTeuSVdmn3GO0cInQ+k2hv6f4xl9fV+M3P6BtMjQi8mVetzO3MxHu02dOow2sXwu7bf1wlhq0o2YlGq7Qzhpm1c+Ke0s6vHWKN4Gp/g7gJasvo6Ef8ux4tYgtuEa9/xDO+p0ud25mELVgsL+56MdtYIefZrYYU8mtWwJIliYWyR7LtkY8o2j69HxL6tL9ltQqo4M6fedhLlQveheEXvE0FHVgrHpfdwFD4S7q6XFBSSh0Qxp+fjyS7lnTjmjli/ss2uiK8fCEe2q+K4m3NqTZMoPtEL8Jqw+G7MY3i+ELY+x9GxbXUU8lIBIXlJVP8F2tA5Rxf19bHYZ58Q8o8sqS9RzOeFQio5iGuyGLRy9DIhBPyIi4VQBi8IR5ZVwjFqR05Bs5Eyvk5gLQ4X8vOeQYvtwhach504Uefz8phwGvqHxfhGuKfudOC/SFh1b1UotBOJwe/osr6uiM93ynh86UMiv89zTN3hdyu7K9D2v+Zl4QPs7GELqRkcrQ+wTcMWUlM9x+MOPCHku/dVf3lUMwtYK+zivXjO9OvPmpqampqamprS/A30EDmXOA60gwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x^{3} + 4 x y + z$$"
      ],
      "text/plain": [
       " 3            \n",
       "x  + 4⋅x⋅y + z"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=x**3+4*x*y+z\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABsAAAASCAYAAACq26WdAAAABHNCSVQICAgIfAhkiAAAAWpJREFUOI3t1D9I1VEUB/DPE0NI3DQEh0BxcAwhECGeIEok4uAkzrY2hK6N2hBIa0NDTYo6uJiBgyDq5KSDIA4OItaQkCLZc7j3F6/L+ydPaOkLhwvnnN/3e879nXv4hxjHe2ziBwr4VOWbF/iCE1ziCAvoqya2FwUucFCD2FzMOccHzGIR1/iNyUpiA+hGDvkqYu24wSkeleApCF3+QWOStFGpkgSP0YAdnJXguUBbsbPhDuQpDoXreorWJPYMLfha7Ew7uwu+YwbvsI8VfEMXRrGOl7WS5dU2jWNRuFBkh5hIE+u5RpgWpu+j0FEzeoXB+Iy3tRLlVe4siy+ViD0U3t0NOjNnPZ2NxLPUBP/EbuR/ch9iTfFsKxPP/Nf3IbYZzyl0JLHn6McVtjJnLkkai0bYEMPCz86Iz/G6qNA1DAoPeFnYJj3CFefwCvPlqn3j7xFO7TjJfxAJt4XF/UvYJqsYKifyH3XhFttdWDT6O44NAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$18$$"
      ],
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs([(x,2),(y,1),(z,2)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOUAAAAWCAYAAAA/z1uhAAAABHNCSVQICAgIfAhkiAAABOtJREFUeJzt23uoFGUYx/GPKZZhdM+CgiArC62IiIKKsCAyIrpA9Ec0YVFgVH8UUSQtgWiZaHeQiNMVhMAgonscKEvINBOSIsuKNEu0G12t0x/PHFyn3T1nZ2fOrDJfeGH3ve3zO8/zzry3Q01NzR7LXRjCI1UbUhJz8DF+TtP7uKhSi8rlTnwgtP6AlzC9UotquuIMfIm19txBeQlm4Vgch3n4GydVaVSJvIZrxUCcgeX4DgdVaVTN6NgfGzATg/bcQdmKbbihaiPGiMn4BxdXbciezl4F9LEUL+DtAvoqkqvFdHoI1xXc93hcJQL1vYL7zkOZWofZT8TLtpL6b8fBQtNyfI7f8RPexWzFxPBYcB/ewjdCwzaswT1CY2Fcjw8xMf0+qD/elEfhR/yi2ECdgV+xA9vFdLZqytKaZZkIovEl9d+OG4WuTXgO8/Gk0DwkXgjjxtimPPyFlcL2BXhYrNmH8K3wY88cLzYApjXlDap+UI7Dm2JKvVCxgToRU3GaCI6t8m9+JMK2c3uwp0ytzSzEZqF9rJkppszZN+Lh+FpovnwM7Ej05q992uTPS/t9rF3D19MKl2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GBJdHFL4LiAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{4} - 4 x^{3} + 4 x^{2} - 2 x + 3$$"
      ],
      "text/plain": [
       " 4      3      2          \n",
       "x  - 4⋅x  + 4⋅x  - 2⋅x + 3"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = x**4 - 4*x**3 + 4*x**2 - 2*x + 3\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAAaCAYAAABvoxoyAAAABHNCSVQICAgIfAhkiAAABd5JREFUeJzt23usHGUZx/FPoaIgRkSQS5QYwz0gSrgmNpAqUTGEIPoHJMISLhowBAIENRA2JNiCNgUVUIzmIJcENGK8RCXYHAoFAgWK3InoUUNpFVvuCoLHP5536bI9uzs7O7NzTne+yeTsvjPzzO+Z87zzPu8z71JTU1NTMWfgj3gxbXfjc5UqGl++gWl8r2ohJfF13Cfi7J/4FfapVNEmytE4Erthd1yC/+KjVYoaQw7BX/CQTbdT/x4niY68L27BGmxbpahxYR2+XLWIMeK9eBoLMWnT7dSdbI03cVTVQnqxWcn2vyTSs2mcUoL9zXGcuNl3lWC/F+8XPt2CP+HfeAF34mTl39squQY/w7KqhXRQdry9R/xf15Vgux+X4g/4u4i1dXgQF4lYHAkfwvN4SfE3eV+8jDewXqTjo+Yrwq/VuAGL8GPh87QI+nkV6CqbU3E/tkjfJ82OkbrMeGtxk+hIm5dgux+v4x4RY4vxXTHfn8Yzwv9SmYfbRIr2LcXf5C2wKw4Qnek5oy9gLBRpWOeIvCP+Jnw+dgQ6Gulah4/gWnuIgtGebW2T8nfqhmK0lx1vkt1nRdzloWE4X9/Vpf2SZPeqVkNZKeKZIuhPwit9jr01ifp8R/s8TKR9izv2vS5S3pWiQrkKZw2leHCWiWro/zra1+D76fPhHfvy+Fom56RrntNl/x54DcvT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Qtlh+IioiJ86SkFNGz85d01C1pv5J5OfSufcU7a4IWjqP5+bVL6vDcOPdguSjXuNdr16w+hH6rno6z64UkzxnhNV/xfEwp+m+qegNTPwS5FxHFi1kBEwTr7WjCnHixFkNvzSqmzGydeaMWMXfA0/FJXkRxS/2Ge2ME6+1owxp4kRa734lc/OvQ+f04yTrzU1NTU1NTU1NTU1NTU1NUPwf3N6Oabyn9tKAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$- 4 x^{3} - 2 x + y^{4} + 4 y^{2} + 3$$"
      ],
      "text/plain": [
       "     3          4      2    \n",
       "- 4⋅x  - 2⋅x + y  + 4⋅y  + 3"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs([(x**i, y**i) for i in range(5) if i % 2 == 0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.2 将字符串转换为SymPy表达式\n",
    "sympify函数（sympify不要混淆 simplify）可用于将字符串转换为SymPy表达式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIEAAAAYCAYAAADdyZ7bAAAABHNCSVQICAgIfAhkiAAAA9RJREFUaIHt2V1oXFUQwPFfP5AiFb+tgj4oFYpUI4IPguKmKorgR7Uv9sWVahEUEVFEUSyCtqJFbbCCDxpFH0oFBZX4gSDWSqHFVgoGRSUo1obGb/Fb48OcJdvtbnL27mY3D/cPFzbnzsydOXfOuTMnlJR0yD3YiZ9xAK9heV89Kuk5b+EG8eLPxCvYj2P66VRJf1mMf3FFvx0pyWd+l+0dkWx+32W7OTyCd/E1fk8+7MYDOLYP/hRhFYawTXxiJ/Fipu4SsQA3iXhvFDvz52I+fsIHWKP77/0gtoiJXzCbD2nBX9iBZ7FBTOZOMZHf4JQ++NQue4S/v2BUe0mwNskP4ub0ex9ewnoxLz+m8Zcxr5uO13gU32JpQf2qcLBSUH9Ri/GHkt3NBe32kkGcLl5QRXtJMIIJsQBXiE9y44o/EV8lu9e2MvR2ErimYXwehtO9DU30NmIcZ2Q63IyqzpKgFQPJ7jsN40Vj7RUV+UlwJP7Ecxmy9ya7Q60EBsR35RMHb+kbk+IzTXQ26TwBmL0kuC/Z3dgwXiTWXlKRnwSrk2xOQX5Xkn18OqHhJFRNf9cyZ4tDt5fNooBZIbaa2rU4w5lGqrqTBHdinQhyW7L5MY5vIjssP9ZeU5GfBFvxq9afxBoLsTfZvXQ6wZNFNTmGW5PCmzisiexki2tdhuONVHUnCfY3+DIiKudmtBNrr6nIS4JFopDcmmHzsWTzjRwH1puaxO04PEepDca0TqBm13CBZyzBSnwqquRzWsgVjXWsDf/bKfBqVDL1rkxyq2eQuy3JjWo4zFvYQuFA3e81+G2GB7TLEziqYexsXIXnxQTXs6fAM8ZFn/wRPsMLmh9pF431C/zRhj/72pBth5WiPZ5udd+CJ0X9c5GMc5zr8J9o9ybxdMdu5lE1O4UhcXYxieMaxvsVaw4VM+8EC0RbODKNzO3Jzl6ckPPgy0VW7RWF1Cj+xrIc5Q6pmr0kGE+2j64b62esOVTMnASDSWZti/t3p/u7HboAmnK+2Aq/xElpbFUy8mqOgQ6pKp4Ey0RX0sh8U4dF2+vG+x1rDhUzJ8GQaHObFb73J/1dZviHXq0mGMDr4nz5ErE9EseLu8S3+gLRcs1FLhMnlu+Lb/V3YmIuxGmiY7gpyc7lWK9OF1NJfZ6pwnhCtMD18h+Kna6e6/GgSJBtoihsZKzOrqVikn7AWU2ELxYZtSMjiE6oKr4TLMdTooCcwD/iJe8U7WptJcyVWFuxzvQdxlid7Llp7I4CdibxXte9L+k5D4uXeWq/HSnpH6OKtc4lJSUlJSUlJU35H65pQ6uzsDbWAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{2} + 3 x - \\frac{1}{2}$$"
      ],
      "text/plain": [
       " 2         1\n",
       "x  + 3⋅x - ─\n",
       "           2"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str_expr='x**2+3*x-1/2'\n",
    "expr=sympify(str_expr)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC0AAAAUCAYAAAAZb7T/AAAABHNCSVQICAgIfAhkiAAAAmZJREFUSInt1kuIjlEYB/CfS0yUcR8rclkoSomykbCw0ChkI7EgKSVJ0ZTYUKLI5LZiZyGsmIVELisy7pfcvky5E7nfLc6Dmdf7ffPOiIX86/S+7zn/5/k/57zPec7hH8B6HEET3uIZGrEafXL4JXwt0x60olWDz9gS332wAAdwM/Rf4CTmo+N3ww4ZRx9wFlfwCN0xDmNwL96bMkH3xOacoF5hY4WgF2InJuEoFmE77sf33ZjYDFRjH2ZJC9ICVWUE1gZ5W6a/FK09aMATdIrvSajVbEUDA6QJfMXMtgiMCqPDmf6S9gVdjffYVZBfF/r10LmgUW08L+SMdcUcDMTr4ByX8rUcpqIL9hfU/xjPT5VIy7EGm3BCmuV59MvwSvI34W1MqOB/r5Tz5dKxOTrjYvidUon4IBNEg7Qpslgt5WINumEkduAL3khplUUVXkbgRbAxYjhYkK8G03Fdqh6j2yh0IGdsWozNLuBnSXCvondB7R8YJG2cSwX5w0Lsac7YrvBV3YqPxeHjslRB2oXGcNK3ALdHcN9l+jtJZa6hFfulYX8R/dsWZks8DEe9CnCnBPdKpn9i9C+sYLsiOI0KLNBw+b+ho5+Hy6lm/SPk59kg3Ah+XWasXiqFeZsaVoXdmTK+0fIYX4oNUo29JeVjjVS6hkgVZbKfq7cGK6Uj945UEYZKNbgKh6RN/KGZRpNUJsfnxDIPu2NS9dK9I4tScH5gJLbinJR3n8LwdASYnfkE7ME1PJcOgMfSqTnXr/easdIqLssJRmiUu3x9b8fK2P4xrAvhwX9b+HdwVfqL//EffxLfAMUhrnYk9BKYAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{35}{2}$$"
      ],
      "text/plain": [
       "35/2"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(x,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.3 evalf\n",
    "将数值表达式计算为浮点数，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMYAAAASCAYAAAAANKFkAAAABHNCSVQICAgIfAhkiAAABcBJREFUaIHt2mvIZlUVB/Cf02s2kiFmNRDRVcgSLCPLwHg0Lcaypqn8IJhSVlCkdlMrg7cLWBahGBSDQYYE3ZyiqbwUmRpKGUl2oTR9yYFCtMxJJ23Gtw9rn54zZ85l73Oej88fHs777rX2/q+1zr6ufVhiiSV68VScje24C7vxL9yMd2LDiDZfj+uwM7V3N76N4xbIncvRhTOwnn5nL8Cus2rtdf32ttR7Ky7HTXgo6V3VY/ci3lef71N8KeWp43h8F3/Do+l5HU5p6JXGCw7AO3ArduER/Abn4Al1xZXa32/Dl5MhP8Nf8QxsxRXYnHTWB8grfA7n4wF8D/fjBXgT3oK31xwZy13C0YZnieD+G09ukY+x63Z8soPveJyIH7fILsLRyZadeGGP3WNtq2PId8b7UspT4SJ8WrzHHcK3w/FSzPCjhm5JvOBKMUjvwzfxME7CZXi1jnidiFPtP9NsEkFfF50tB5vETPJ3PL0hOyG1dfdE7lKOJg7AT/AXfF77bLbImMAtqc4bW2Qn4Ihk18zwDDjFthzfh9DnyxieqlNej0Na5Ac2/i+N1xbzPnF4o93tSXZWT/1WfCxVvDxT/xVJ//sd8ofEUjaFeyrHuXhczBSryjtHaUyOSvo7NZbtFszkbQ3G2jbV91xfcnk2iA77MJ5WYEeFmeF4fT3pvK9FVvnz67pBOfhveu7J1L8Tj+FY+45OIkiHiJlkCvcUjiPxWbGE3phpR65dXXh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V9KrBreF97QqLOWyp/T0t6BYu97qzjk7BH3DTvsf/Ifw13K0YeKvzmbjbWLGKAlh+4hrrUF2tbWTt+KUerLWJ7DRIbxHrGdekB82dB2t1C1lxsv+Ii43X5QDIZ78BXt/XeJJZZYYoklllhiiXH4H2AI057P0DVEAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$2.82842712474619$$"
      ],
      "text/plain": [
       "2.82842712474619"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=sqrt(8)\n",
    "expr.evalf()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SymPy可以将浮点表达式计算为任意精度。默认情况下，使用15位精度，但您可以将任何数字作为参数传递给evalf。让我们计算前100位数π。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABQAAAAASCAYAAAAEwnPAAAAABHNCSVQICAgIfAhkiAAAEg1JREFUeJztnWnMNldZx38tL9JWC0jRNijBUtBCawoopYjCvAUaWUpKAT8QllelihKBiBQoGu64IpKGRaE27Ev4oFIaVimkUCgQlSWAbAV6KwReS0FoKbVC+/jhnMkz7zxnZs71P2eu94Pnnzy5n8x2Lf9rm7nnnoGGhoaGhoaGhoaGhoaGhoaGhoaG/zf4a+D9wNeAG4HvAJ8EXgAcZzzWY4GXAx8CrgN2gDcZ9n9i3GcHeEpFGdvBccd/BxPbHwH8FvAx4HrgBwSfPB24VWL746K+lwBfJvjxe8CHgd8GjlzQ79eAfwK+CdwUP98LPLyCLQq/Vhk9HhH1/nqU9VXgH4D7T2xv8fOBGZ36v5sLZfSw+EzlXs07q4/HyMkxyI9Jz9i32qL42IMXqwzFxwfwyZftzPHnasXPAq8BvkHgfQu8BPjJxLZqjCm54pFf1h5m5eQAGvcl/Ts3j9eux6ocD70OoPGyndk+lWMqj5acVPTqkZtjJb3FaovHLDJGTq1Q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WvHpY8Xrseq3K89AIbL0qObdB4tOSkx5ywZMdc3bPYAj6zSAob5muFmvtWOZbtVe4ttvTyPeYqsMcL2PhXesuG9evxFHrZU/Gi+GvtuVLt317zrsVnXudTyj6Kbh4+VvSycFJSX8bYMJ9fa/dJpYbXsr/XN2W7YkvOfttK+yg9f+1aCfXOXRoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoafPF/XDNo7k0xF4cAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068$$"
      ],
      "text/plain": [
       "3.1415926535897932384626433832795028841971693993751058209749445923078164062862\n",
       "08998628034825342117068"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pi.evalf(100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "为了在一个点上用符号数值计算表达式，我们可能会使用 subs后跟evalf，但是将替换值传递给evalf使用subs标记的对象更高效和数值稳定。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAASCAYAAABCd9LzAAAABHNCSVQICAgIfAhkiAAABjpJREFUaIHtmmmMFUUQx3/gohyuIl4blcgRFQQjguAtIkrEgwAeH4hEYkCiRjGeICa+GA/wIOAV3SDeiYkIGo0HuGo2okSiEANeq4CCsigggkBAAT9UDTs7dM+brvf24Yf5Jy+z21Vd/6p6/fqoHsiRI8f/CscAs4DfgO3ASmA6cEgFbF0CzANWA9uA5cDrwBkO3THA7iKfnRl8HB3TH+uQtwKuBRYCm4GtwGLgZmC/FLshsVSKZypQB6xS3Q3KcS9waApHHMXyZeWxxh/iVyl9zgHeANYgY3kNkveLy+lXd2CtKr8JTAE+0v+/I/uXZLE1VWXrgJmqPxvYAewCrk7o9wEKn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fWUSYo/LLUzhnqE7BI+9I8+1Q2md6Ck+EdshA2UrzUnQ5YtkXPItVPyrolDtfPp5iSMZv8csay0htW+TxLVpoJlo54kWYj/U5BNmaxquX1cBZmoiFFEeorWjG8JV6o/YdHnlb5I2DXUj104XtKbK+wCnAp8gslmX7MFp5XwT+ibWXGsu+4jlKn9E2r9z58vEUQzJ+i1/WWOqR899xwP7sncve+lxZAkczhF7Ed0cqU67LyBBbV2lbI3B0Qn8o8sPahv9NnOh1n7c98mIo4N8iHORo648UPjaz9xbPGktL8/SgqdwfR2uaimILHHIXCvjzZeUJjT/UL2ufV1R+f6L9QiTHG9n7eiQzR1Xi/xuAz4DHke3ht8iF7yDkSmFyQr8O2dd3RWYBq63ZyJ3VBao3FxlYPYFLkUPwRKTM7kJUfKn1yEvBfGQgL0UGQi+kMLAd2aIk766ssbQ0z0XIlqkeeTtjPVKRHIgM7kZgXOas+GHlCY2/UrgVGbeTkfvVL5AxPwJZxcchP8KyoTPyvtsaZMn9GTlfdXLorkR+2V3KYKsNcAuyLd2ELP2/I1cKQ1L87Ul68SULCvhnwTuQtzA2IoNhBbJ6d0mxZ4mlpXl6A08hRY51qvsXcr4p4P5OfCjgz5eVxxJ/iF+l9OmE7NxWION4PfIGUpaXUqx+5ciRI0eOHDly5MjREvgPEeF3KoszZ1YAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$0.0874989834394464$$"
      ],
      "text/plain": [
       "0.0874989834394464"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=cos(2*x)\n",
    "expr.evalf(subs={x:2.4})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有时候，舍入误差小于计算表达式值的所需精度。通过将chop标志设置为True，可以删除这些数字。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIAAAAAWCAYAAAAI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Ah1q9L7OlR60OWjlr3yXvUehNejumdOMd8wfbIgD7j1PefpquZAxC+J7wkvN78hR+EGGLQJ88cGsvSQkm/celraWlpaWlpacnKPxQBBuIc6BRxAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$-4.0 \\cdot 10^{-124}$$"
      ],
      "text/plain": [
       "-0.e-124"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "one=cos(1)**2+sin(1)**2\n",
    "(one-1).evalf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAM5JREFUOI3N0rEyQ0EUxvEfJcMVWhoZ8Qpq75PnoDJ0Kl5BK0U67yAUiUYmpZGYoRDNuePOkXszYxS+5ps95/x3Z3c//lC7uMIz3jHCOVpNUBsTzHGDU/RjfY+dOvA2hrqpfhb1y0XQfjSHWE29DUwxw7o0cBzew2cCX3GHNRxl8DD8oeYaj+GdDBbhLzVgWd/K4DKthM8zWO5YWKzN6lwVHIR3asCD8B9v0Lb8O97Ed2T9KgDlqdXInfiO3EBD5GAP1xjjA0+4wHYT9I/1BRgnMa7SDNsAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(one-1).evalf(chop=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.4 lambdify\n",
    "subs和evalf适合做简单的表达式计算，但如果你打算在多个点来计算一个表达式，有更有效的办法。比如说，如果你想要在一千个点上计算一个表达式，在只关心机器精度的情况下，使用SymPy会比NumPy和SciPy这样的库慢的多。\n",
    "\n",
    "将SymPy表达式转换为可以进行数值计算的表达式，最简单方法是使用lambdify函数。lambdify就像一个lambda函数一样，将运算交由指定计算库（通常为numpy）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.        ,  0.84147098,  0.90929743,  0.14112001, -0.7568025 ,\n",
       "       -0.95892427, -0.2794155 ,  0.6569866 ,  0.98935825,  0.41211849])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.arange(10)\n",
    "expr=sin(x)\n",
    "f=lambdify(x,expr,'numpy')\n",
    "f(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "您可以使用除NumPy之外的其他库。例如，要使用标准库数学模块，请使用\"math\"。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOwAAAASCAYAAABYSzJ9AAAABHNCSVQICAgIfAhkiAAAByZJREFUeJztmmmMFEUUx3+sCwqyqKCwUQkCgiBrQBS8dcGAomIwHh+MIB6JGqKQiCJEw8Qol4gY0BhEFI/4ARUlKoqiuELAmxhAOXfwYEGuhRUQ2GX88F47vT3VPV01jYlx/kmnZqre/72qflXVVa8KiiiiiP80TgfmAFuAg0AamA6cdJR1NQHuBFYAdcB+4AfgAeCYEP0uHIBrgUXAb8ABYBMwD7jIIDsZWAz8qrK71MZ4oE2IfhdOEEOBjD53h8jcBMwAvgT2quzrMXRfBrwN1CB+qUHexzUJczzEaYuLHRs/tlHb84ENKr8HWArcBZRE1MnGjotP0mTfT/DZGkXsDGxTwXeBScBn+v9n4nc2F12vatk2YDbwLLBa895CBmcQLpzJWr5DOZNU9hBwBLgtIH8ImRDmqOwM4BvV8TvQ3mDDheNHe6AWmYSiOvlKLa8DfiJe53hU5bYDLwMTgFlavykJcmzbYmvH1o/3qvwW4A1gIuKfWpLtLy4+SWs9UoZndBTxYzVwfyB/mua/kMew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w0VXPfA0MsCaA62AqxHn90IG5OqAHlvOdZp+bqjTfuBr5J2cG9qyLDarnR7kBiRsOC2R99Qd+IvGy67xKvOi/p8e044Jnk9qQ8p3a9q8AI5rW2ztFOrHUchHYxUS3Am7nJBkf3HBH5r+czLjDzp5lRqolfBHd8uAS5ABsIL8SFLXUORccy7ZaJ4rx5v1w44OvPxDMe2cqmlDTHkT5yDwUohsb6QzLEU69XILO0FUIRNcF6AZuW2s0DRdAMe1LbZ2CvHjGCTotxIYQDZ4aULS/cUW3hbAdBIC2F+c6IxEYU2H57a6Whl09EE2+3WYlx22nFvI7nlPC5QNQiaWA2RvYXXDvFwqIRs4WxYoc+GEIUVyS2K0LAM8EcgfgLS9lsbHYK4cE1JEt8XGjq0fPTymvG8J37P64WrHQyX5fdIjpC4dkC1ChohIe/A64USy1wnXGiqW1rIzEtD1FRIJnKmyC5BZdx9wVUh9bTklSCg+g+x35yJXzxYgLz+4hxuFfKEXI0Et7zrbRpWtAc4O2HDhhCFFdCcfAryijxdN3ejLmxqQb0u2E1Rp+TzknR1GbhsF4cJxaYuNHVs/AtxONhL9DOZrgMMDHBc7tj5JIduHhcgNuMnI1ccDZKPXzYhAe+QeZw3yqd+MHH6bZoE04QPWVtdDyM2kWmRpVY18hcN0u3KaIoNqBeKEemSv8D65EeUK4Dlk+bRDZfcgd1tTIe1w4YQhRXQn98rDnrSB0xpZ5VQjPtmJ3OSJuhDjwgmra9RqwcaOjR/99qOeJf+CnXRA/grgTeR+fS0yOW1HJophmO83F1FEEUUUUUQRRRRRxP8VfwMoHr6mSgTAkQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$0.09983341664682815$$"
      ],
      "text/plain": [
       "0.09983341664682815"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f=lambdify(x,expr,'math')\n",
    "f(.1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "要将lambdify与其不知道的数值库一起使用，可以传递字典{sympy_name:numerical_function}。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAASCAYAAAA6yNxSAAAABHNCSVQICAgIfAhkiAAAAJ1JREFUSInt1LEJAkEQheHvRHswUxHBMjQyNbAUC7AHW7APAxswM5MrwEgL0OA2kOOEc1fUYB8M7CzD/94kw59phS0OuOKO3TdZxzB4wykxQBRrjgkKzBIDtGJ1a/0+0qxJrVidDxpGKQfIAXKA1ABjTNGLBRS1fhkK+ljgrLrncMH6ab7EAKPwTmGBjepkvqq6SRn+hw3LvcvK+o0eK1k2H4qHdA4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1.1$$"
      ],
      "text/plain": [
       "1.1"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def mysin(x):\n",
    "    return x+1\n",
    "f=lambdify(x,expr,{\"sin\":mysin})\n",
    "f(.1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5 格式化输出\n",
    "## 5.1 自动输出设置\n",
    "```python \n",
    "from sympy import init_printing\n",
    "init_printing()\n",
    "```\n",
    "或者\n",
    "```python\n",
    "from sympy import init_session\n",
    "init_session()\n",
    "These commands were executed:\n",
    ">>> from __future__ import division\n",
    ">>> from sympy import *\n",
    ">>> x, y, z, t = symbols('x y z t')\n",
    ">>> k, m, n = symbols('k m n', integer=True)\n",
    ">>> f, g, h = symbols('f g h', cls=Function)\n",
    ">>> init_printing()\n",
    "```\n",
    "如果明确不使用$LATEX$，那么设置参数use_latex=False给init_printing() 或init_session()。要明确不使用Unicode，那么设置参数use_unicode=False。\n",
    "## 5.2 特定输出函数\n",
    "* str\n",
    "* srepr\n",
    "* ASCII pretty printer\n",
    "* Unicode pretty printer\n",
    "* LaTeX\n",
    "* MathML\n",
    "* Dot\n",
    "\n",
    "### 5.2.1 str\n",
    "使用$str(expr)$或者$print(expr)$方法,可以获取表达式的字符串格式。表达式的字符串便于阅读。另外，由于表达式的字符串是正确的python代码，我们可以方便的对python代码进行复制粘贴。$str()$表达式的形式通常与输入表达式完全相同。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Integral(sqrt(1/x), x)'"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(Integral(sqrt(1/x),x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Integral(sqrt(1/x), x)\n"
     ]
    }
   ],
   "source": [
    "print(Integral(sqrt(1/x),x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2.2 srepr \n",
    "表达式的srepr形式主要是为了显示表达式的准确形式。我们将在高级表达式操作部分中进行详细介绍。要获得srepr形式，使用srepr()函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"Integral(Pow(Pow(Symbol('x'), Integer(-1)), Rational(1, 2)), Tuple(Symbol('x')))\""
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "srepr(Integral(sqrt(1/x), x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "srepr形式主要用于理解表达式是如何在内部构建的。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2.3 ASCII\n",
    "pprint()函数获得表达式的ASCII形式。如果终端环境不支持Unicode，那么函数默认使用ASCII格式。否则的话，需要设置参数use_unicode=False。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  /          \n",
      " |           \n",
      " |     ___   \n",
      " |    / 1    \n",
      " |   /  -  dx\n",
      " | \\/   x    \n",
      " |           \n",
      "/            \n"
     ]
    }
   ],
   "source": [
    "pprint(Integral(sqrt(1/x), x),use_unicode=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'  /          \\n |           \\n |     ___   \\n |    / 1    \\n |   /  -  dx\\n | \\\\/   x    \\n |           \\n/            '"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获得外观表达式的字符串\n",
    "pretty(Integral(sqrt(1/x), x), use_unicode=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  /          \n",
      " |           \n",
      " |     ___   \n",
      " |    / 1    \n",
      " |   /  -  dx\n",
      " | \\/   x    \n",
      " |           \n",
      "/            \n"
     ]
    }
   ],
   "source": [
    "print(pretty(Integral(sqrt(1/x), x), use_unicode=False))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2.4 Unicode\n",
    "pprint()函数也可以获得表达式的Unicode输出形式。如果终端环境支持Unicode，那么会自动使用这种输出形式。如果函数无法检测到终端环境是否支持Unicode，那么可以设置use_unicode=True，强制函数使用Unicode。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "⌠           \n",
      "⎮     ___   \n",
      "⎮    ╱ 1    \n",
      "⎮   ╱  ─  dx\n",
      "⎮ ╲╱   x    \n",
      "⌡           \n"
     ]
    }
   ],
   "source": [
    "pprint(Integral(sqrt(1/x), x),use_unicode=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'⌠           \\n⎮     ___   \\n⎮    ╱ 1    \\n⎮   ╱  ─  dx\\n⎮ ╲╱   x    \\n⌡           '"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获得外观表达式的字符串\n",
    "pretty(Integral(sqrt(1/x), x), use_unicode=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "⌠           \n",
      "⎮     ___   \n",
      "⎮    ╱ 1    \n",
      "⎮   ╱  ─  dx\n",
      "⎮ ╲╱   x    \n",
      "⌡           \n"
     ]
    }
   ],
   "source": [
    "print(pretty(Integral(sqrt(1/x), x), use_unicode=True))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2.5 $LATEX$\n",
    "使用latex()函数，获得表达式的$LATEX$输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\\int \\sqrt{\\frac{1}{x}}\\, dx\n"
     ]
    }
   ],
   "source": [
    "print(latex(Integral(sqrt(1/x), x)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\int \\sqrt{\\frac{1}{x}}\\, dx$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2.6 MATHML\n",
    "数学标记语言（Mathematical Markup Language，MathML），是一种基于XML的标准，用来描述数学符号和公式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<apply><int/><bvar><ci>x</ci></bvar><apply><root/><apply><power/><ci>x</ci><cn>-1</cn></apply></apply></apply>\n",
      "------------------\n",
      "<apply>\n",
      "\t<int/>\n",
      "\t<bvar>\n",
      "\t\t<ci>x</ci>\n",
      "\t</bvar>\n",
      "\t<apply>\n",
      "\t\t<root/>\n",
      "\t\t<apply>\n",
      "\t\t\t<power/>\n",
      "\t\t\t<ci>x</ci>\n",
      "\t\t\t<cn>-1</cn>\n",
      "\t\t</apply>\n",
      "\t</apply>\n",
      "</apply>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sympy.printing.mathml import print_mathml,mathml\n",
    "print(mathml(Integral(sqrt(1/x))))\n",
    "print('-'*18)\n",
    "print_mathml(Integral(sqrt(1/x)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.2.7 Dot\n",
    "sympy.printing.dot模块下的dotprint()函数，将表达式输出为点格式。点格式可以使用Graphviz进行渲染。Graphviz （英文：Graph Visualization Software的缩写）是一个由AT&T实验室启动的开源工具包，用于绘制DOT语言脚本描述的图形。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "digraph{\n",
      "\n",
      "# Graph style\n",
      "\"ordering\"=\"out\"\n",
      "\"rankdir\"=\"TD\"\n",
      "\n",
      "#########\n",
      "# Nodes #\n",
      "#########\n",
      "\n",
      "\"Add(Integer(2), Symbol(x))_()\" [\"color\"=\"black\", \"label\"=\"Add\", \"shape\"=\"ellipse\"];\n",
      "\"Integer(2)_(0,)\" [\"color\"=\"black\", \"label\"=\"2\", \"shape\"=\"ellipse\"];\n",
      "\"Symbol(x)_(1,)\" [\"color\"=\"black\", \"label\"=\"x\", \"shape\"=\"ellipse\"];\n",
      "\n",
      "#########\n",
      "# Edges #\n",
      "#########\n",
      "\n",
      "\"Add(Integer(2), Symbol(x))_()\" -> \"Integer(2)_(0,)\";\n",
      "\"Add(Integer(2), Symbol(x))_()\" -> \"Symbol(x)_(1,)\";\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "from sympy.printing.dot import dotprint\n",
    "print(dotprint(x+2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 6 简化\n",
    "## 6.1 simplify\n",
    "接下来我们做一些有意思的实验。数学符号计算最有用的特征之一是简化数学表达式的能力。SymPy具有许多功能来执行各种简化。还有一个通用函数 simplify()，它试图以智能方式应用所有这些函数，以获得最简单的表达形式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(sin(x)**2+cos(x)**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAASCAYAAAAZk42HAAAABHNCSVQICAgIfAhkiAAAAU1JREFUSInt1b8rRWEcx/GXHxnsBmVDmdx/gDrKZJIsNmX1F5hsDEwGZbqDxWaUxSClLEoxiO6EMhCFiGs4j7pdXOe53UPiXafO832ez/f5fM95fvDPtzCOJWzjBmWs/qijOtmXmr/FkV9cyBB60YREjUKaq9qbYfBYVbwJxdA33zifX7KF4zBvFAU84xAtFfHFkGylEe7qJBG5tIpBMBnaM6G95v0f/E4SkYV04R4lTAfxBtoa7y2KRB2bfS6IythBe0ZdqUKX5YkxldTStH4iuqx4n8JdxslO8JDVGc4ixkYzgRecS7/Acp6TRZCI+IsjeMQBOqSX0BP6cjIXQyJjIQPSJXSKzhAbD+L1nMzFkMhQSAHX0uXUXdW3FxIM5mDuK0al10FRenKWpfvwLbZQObgHF7hC/wfJhkOC3Xy81mRW7VOv9AOe/vlbvAJAOGPWFb/OwQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x - 1$$"
      ],
      "text/plain": [
       "x - 1"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify((x**3+x**2-x-1)/(x**2+2*x+1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIIAAAAVCAYAAACKYDYGAAAABHNCSVQICAgIfAhkiAAAA2lJREFUaIHt2U9oXFUUBvBfa1FjhYL/UNGVrejGIoogKIxWKAiCaDeurNRFwSoiiBgQu2uRikgXggsJooiQ0oII0pVgBf8UFQpmYyUVNKWCf8GojR0X5047ed55c6edSV/ifDAk755z7nzfl3Pfu/eFMcaowZs4gbXnm8gQcRva2FaQuxL1M5gHbscpPDNKRkPA5Xgc+/EN5vErDgmhqzM1+zGHS2vmXS76YQv24iP8Jv7Ib/WpKfEAHMQvmDg3jiPHdiH8B7yNXXhDcG9jGqsqNXek2GTNvMtFP3wl9PyOGWWNUOKBG8VqeP3cOY4c9+IB/135V+M7IfbhTN0MjuGCTGw56Yd7sEE0fEtZI1DvAdidJtuUiR1MsYcq46swlWK7C0gsBSYFn72Z2IsptjkTq9NPsz1oKW+EOg/AYSzIb5I24h98bXEnvZwmbdIqelZweiUTuy/F9mRidfpptgct5Y1Q54G1woQjNRNMpQm2puvOyntXfnN2PrBGaOjV8etS7LPKeIl+mutBS3kj9PIA8Xxsi9tfL1wnduez2JHyP8CFpWyXAHsEr/drcuZxvDJWop/metBS3gjkPQB3OtPZddiV8tr4GJcUfvFsV13Jp1RQN55KtTO4rCbve7H6u1Gqn2Z60BqwZpEHa7oC8+nnxX0m+LHr9234o/CLj+LPwlziWDgInsCr4vm9CT/V5E44o7eDUv0014NBkPMAXCs66lBN8SPieDWXcl8bNruzxNOCzxFc1Sd3tdBwtDJeop/metBSfkfo5QHiCHTC4m7vxv34W5h9pbj9nsRNA9EdPp4TBnyJKwryb075+yrj/fTTXA8YrBF6eXAa0ylhfWX8LnH7+xbXpLEtKffAQHSHixcSh8Pq9wTdeCzV7MjEeumnuR500FLeCHUeIG57bfG87WCjeOU6hxsq+Z+n/LuL6Q4Pj6bvXhDvC3ZmPlszde+kmuszsZx+muvBg+I4OyVOLm1xu++MZd8TqPcAcQQ6jk/T9fp0/TNuyeR3Xkx8Mgj7IWGn/rvuDys168QGqdcKrupneXswm6np58FpPJ8muXUoVJuFJ/VfvStZP2UeII5Px/DeqBktMSbEcWy6T95K1U+NB7n/Pi3gC1wkNmEnR0pt6bABf+El8bzvhZWqn3IPxhhjjP81/gWO9lBHKMQ+5gAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(x - 2\\right) \\left(x - 1\\right)$$"
      ],
      "text/plain": [
       "(x - 2)⋅(x - 1)"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(gamma(x)/gamma(x-2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们看到simplify() 能够处理大量的表达式。它只是应用SymPy中的所有主要简化操作，并使用启发式方法来确定最简单的结果。但“最简单”并不是一个定义明确的术语。例如，假设我们想“简化”$x^{2} + 2 x + 1$为$\\left(x + 1\\right)^{2}$。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG4AAAAWCAYAAAAhKqlXAAAABHNCSVQICAgIfAhkiAAAAs5JREFUaIHt2E/IVGUUx/GPKS1CIewPCi4NQirbCgnjPwRBDHXjpp6wRVBEiyIKhJc2CSalgooLeQVbCIGCCuqiBAuCBAUhF0UMLVIx+icYFGWL87w0TjNz33vnzozV/cKFuc99znnOb86955770PC/5C18gV9wEyfxxEQjapgVZ/GCSNaTOI7rWDjJoBrKMx9/YOOkA/mvc1/N/hZknz/U7LeIh/CieOK/xq/4GZ9iu/p1joqt2IcL4vVzB0fHsfAxXMLccSzWwUtC5Hf4EO/iMH7K4x9hzphjqsJlEe8tXDWmxO3CNSytaJ9EoK0KtqtFee5+shbh2+x3S8W4ypBU1wCr8Ji4yVoGJK5b6Lk8eXPX+BxM52s7e/jZjeewRpSqcfOx6Gj/7Bq/joP5d6vrWlWto+QTfJXXLsVy0Vx86e5ytzs7O9TDZi9uYFnpMO8mGe5u7ccb2e/7XeNVtBaR1KehpWSpnM4GKZ+/nc+P+ecTul+8RFeLsjRzzK8QaFJ/4ubhSva7vsf1abPXOhuSCSZuiejK2nglG5/B/T3m3ulzTFUINKk/ce9ln6f7XC+jdTYkE0wc0ZXNJOEzPFBDIJ209U96r2O6whqvZturBm8IVNXaLoh5WA0tAxI3r4/RzY7f23G75KJFfIAHu8aexiYcEX9KJ5dL+n8Ze8T7a43B35VVtY5aQ2m2ie7smsj4gVEvmEnqKTOvZT9X8GjB3Lq1JhMqlRvwmxD9iCgzv+PxGgIpIhle9JvZxyU8XDB3FFqTCSTuGVEmvsHiPLY1G5+oIZAikuFE78j2FxVvco9KazKmxM2845bjlNjfWydKB7FVdFHU7ZViD+1e5Hm8I77LLojGpJu2aBDuZa3P5oP4rIIV/m5svsfrM5OXih2GH/FUD2drReY/H0GgnSTV79YpxV3deaPXmgz3xE0ZrKFd0W9DQ0NDQ8O/hr8AHc4FgxMtvkwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x^{2} + 2 x + 1$$"
      ],
      "text/plain": [
       " 2          \n",
       "x  + 2⋅x + 1"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(x**2+2*x+1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们没有得到我们想要的东西。符合我们预期的简化功能是factor()函数，我们稍后讨论。\n",
    "\n",
    "另外，simplify()函数的相对来说效率不如特定的简化函数，因为它在选择最佳之前尝试了多种简化。所以说，如果我们已知需要用哪种简化，那么最好直接使用特定的简化函数。\n",
    "\n",
    "应用特定的简化函数而不是simplify()还具有以下优点：特定函数对其输出的形式具有某些保证。例如，factor()当在具有有理系数的多项式上调用时，保证将多项式分解为不可约因子。而simplify()确没有保证。这完全是启发式的，而且，正如我们上面所看到的，它甚至可能错过了SymPy能够做的一种可能的简化。\n",
    "simplify()的最佳实践：当你想把表达式简化为简单的形式，但是不知道这种简单形式是什么的时候，你可以使用simplify()获得一些参考结果，然后选择特定的简化函数，以获得更精确的结果。\n",
    "## 6.2 多项式、有理式函数简化\n",
    "### 6.2.1 expand-表达式展开\n",
    "expand()函数是SymPy的一个最常用的简化函数。虽然，expand()函数还有很多其他功能，这里，我们只看它-多项式表达式展开的功能。\n",
    "\n",
    "在数学中，由若干个单项式相加组成的代数式叫做多项式（若有减法：减一个数等于加上它的相反数）。多项式中的每个单项式叫做多项式的项，这些单项式中的最高项次数，就是这个多项式的次数。其中多项式中不含字母的项叫做常数项。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG4AAAAWCAYAAAAhKqlXAAAABHNCSVQICAgIfAhkiAAAAs5JREFUaIHt2E/IVGUUx/GPKS1CIewPCi4NQirbCgnjPwRBDHXjpp6wRVBEiyIKhJc2CSalgooLeQVbCIGCCuqiBAuCBAUhF0UMLVIx+icYFGWL87w0TjNz33vnzozV/cKFuc99znnOb86955770PC/5C18gV9wEyfxxEQjapgVZ/GCSNaTOI7rWDjJoBrKMx9/YOOkA/mvc1/N/hZknz/U7LeIh/CieOK/xq/4GZ9iu/p1joqt2IcL4vVzB0fHsfAxXMLccSzWwUtC5Hf4EO/iMH7K4x9hzphjqsJlEe8tXDWmxO3CNSytaJ9EoK0KtqtFee5+shbh2+x3S8W4ypBU1wCr8Ji4yVoGJK5b6Lk8eXPX+BxM52s7e/jZjeewRpSqcfOx6Gj/7Bq/joP5d6vrWlWto+QTfJXXLsVy0Vx86e5ytzs7O9TDZi9uYFnpMO8mGe5u7ccb2e/7XeNVtBaR1KehpWSpnM4GKZ+/nc+P+ecTul+8RFeLsjRzzK8QaFJ/4ubhSva7vsf1abPXOhuSCSZuiejK2nglG5/B/T3m3ulzTFUINKk/ce9ln6f7XC+jdTYkE0wc0ZXNJOEzPFBDIJ209U96r2O6whqvZturBm8IVNXaLoh5WA0tAxI3r4/RzY7f23G75KJFfIAHu8aexiYcEX9KJ5dL+n8Ze8T7a43B35VVtY5aQ2m2ie7smsj4gVEvmEnqKTOvZT9X8GjB3Lq1JhMqlRvwmxD9iCgzv+PxGgIpIhle9JvZxyU8XDB3FFqTCSTuGVEmvsHiPLY1G5+oIZAikuFE78j2FxVvco9KazKmxM2845bjlNjfWydKB7FVdFHU7ZViD+1e5Hm8I77LLojGpJu2aBDuZa3P5oP4rIIV/m5svsfrM5OXih2GH/FUD2drReY/H0GgnSTV79YpxV3deaPXmgz3xE0ZrKFd0W9DQ0NDQ8O/hr8AHc4FgxMtvkwAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x^{2} + 2 x + 1$$"
      ],
      "text/plain": [
       " 2          \n",
       "x  + 2⋅x + 1"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=(x+1)**2\n",
    "expand(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG4AAAAWCAYAAAAhKqlXAAAABHNCSVQICAgIfAhkiAAAAz5JREFUaIHt2F2IFlUYB/Cf9gHFFiH2BUEXeRFZbd1EgqZlERgRSEFFxAlvAwkv/EBIKCgzQyJSvNogiLCw6MPSmwqiYG+swIJiXehiDSvtg6w2e7s4Z3WbncnZM/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[
       " 2          \n",
       "x  + 5⋅x + 6"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand((x+2)*(x+3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于指定的多项式，expand()函数将其转换为一组单项式的组合的标准形式。\n",
    "\n",
    "expand()函数可能听起来不像简化功能。毕竟无论从名字还是案例来看，它是表达式的长度更大，而不是更小。但是通常的情况是，一个表达式通过expand()函数消减之后变得比以前要简化了。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB4AAAASCAYAAABM8m7ZAAAABHNCSVQICAgIfAhkiAAAAOlJREFUSInt1LFKA0EURuFPyROoiM8TCysrH8AiFoIQ0gmCYGdjE+zFQruAlb1FykCKgDYKwSKlmEpBJSn2irLKbpTdLcQDw8CdnzncGWb4AyxiCxe4xRPG6KKB+bLE25hghHMc4gSPUe9grgxxHeu+draC+5BvlCHOYi/Ex++F0s49xUvMrxX5QA0DScdrVYqPQnqZFRpGaNZxliNtRu4GC58XaqngHZ5ze/hglLG2gzausYqHH+z7a1qSTgdYrkIIuyHtY6kq6X5Ie1J3mqbIL2wTp3iTfBTjbzLDyBTKgfxXcFW09J9cpkjOQNujE1axAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$-2$$"
      ],
      "text/plain": [
       "-2"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand((x+1)*(x-2)-x*(x-1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.2.2 factor-因式分解\n",
    "factor()函数将一个多项式因式转化为有理数上不可约的因式。\n",
    "\n",
    "多项式被另一多项式整除,后者即是前者的因式，如果多项式 f(x) 能够被整式 g(x) 整除，即可以找出一个多项式 q(x) ，使得 f(x)=q(x)·g(x)，那么g(x) 就叫做 f(x) 的一个因式。当然，这时 q(x) 也是 f(x) 的一个因式，并且 q(x) 、g(x) 的次数都不会大于 f(x) 的次数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI0AAAAYCAYAAADH9X5VAAAABHNCSVQICAgIfAhkiAAAA51JREFUaIHt2U+I3GQYx/FPq9SuChXxoKJe7B8RtYoiigqjFg+CKOKlFxmtN+vFWwuFvSlqQRQUPK0i6EKhQi+6l4J/QK1oQfwDWlhB3WoPioJVujoe3uxsNs0kb2aSmWHJF8JM3jx58vx+875v3mRoaWmZKvbhGP7AKRzBdROtqGXqeQ+PCR3lehzGSVw8yaKa4g38igsmXUiN3Iwe9kTENqX/QvyLB2rOWzdVvAK34D883VRFNfIIXsYHwi2ghzcL4g9jSfjxBtGk/suEGu9oIHcZTXjVZwG/Y2a0GsfCcUH8n/hGuRG3JjH7C2Ka1D+PL3BOA7nLaMIrsF0YZa+NXuNYuBvbsAEd5UYQDPtB/g/XpP7nhZG7dcjzu4K+zpDn1+bVxkzQ40nS+ZwEC8mFHs60b8BccuzZsspr5ii+S64dy9u4CrtyjhXpZ3gPDuJR3IvvK9RaJ3V71eczLMtfAO4UFnFfW9vzDiaFTHp26ogbPbuSuBdyjhXpZzgPXsIvuLakrjK6Rptp0nSM7hWCUcv4siDJXJKkm+zvT/bnnT1rjZuOOCO2JHGfZtpj9FPNg1eERec9uDS1RS0uM3SNv9MM8qrP9iRgoSDJFTiNRexN4t/FpthqG6QjzgiChpOZthj9VPOgN2CbjagxS9f4Ow35XvW53eqIKeIZq+I/wvkxVQomDzIxb4sRlKZT4byfhFklTax+hvcglkXVvJqrmL9jBK/OTX0/nXxuLklyKvV9D/6KuDCcwN+RsfBzhdiqzFjVu0Ksfob3IJYXcVGm7UY8iNeFTpXmeM3XT5PnVZ/Lhd73YUGC3cIj6VIS+2qd1Y1IR9zo2ShoOJFpj9HP5DzoGv/tKder9MJtSRhBOwYkuF/o5V/hBnyLJ3BN1YonzA7hETk7Osv0s348iCXXq3Sn6eF9XOLsF1B34hB+xH2CuQeE29u4382Mym3J59FMe5F+1pcHsQzyag27BfOeTLXtFF6rL+HqTPyxJP6uemqszEPCInBOeILpCVPpSlve+4W3hIXdlTnH8vQzHR50jXZ7qturPpuEx6tPkv2tyf5vwnScZeXlz8dVqq+RWcVPFYuZ+C3Cou6dAfmy+pkeD7pG6zSz6vVqDfuSJDcNWdw085TyWWE9669CjFd9Ngt/Uh1psqIJMCM8xh8qiVuv+qtQ6FXeP73L+BznCf/FnGmstPGyDf/gOWF9Moj1qr8KsV61tLS0tLRMC/8D+8VeVvNC1ZkAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(x - 1\\right) \\left(x^{2} + 1\\right)$$"
      ],
      "text/plain": [
       "        ⎛ 2    ⎞\n",
       "(x - 1)⋅⎝x  + 1⎠"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(x**3-x**2+x-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于多项式来说，factor()和expand()是相对立的。factor在有理数上使用完整的多因式策略，这意味着每一个因式都是不可简化的。\n",
    "\n",
    "factor_list返回更结构化的输出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUUAAAAZCAYAAACmTzxlAAAABHNCSVQICAgIfAhkiAAABb1JREFUeJztnXuIFVUcxz9rZrvaw9qgBaMHmKZpKb0M8hGuFYEUFUWRtKlECRGEQUqP+0dB2AZLQX9U0O0BZW5sYgVJslIWlZFGlEFJt4g0DbcSK7Rt++N3brveO88zjzPnzvnAZdw5Z+Z+59zv/M6Z35wZweFwOByRGW9aQAK2AX3A46aFOErLGmA78AewH9gEzDKqqFzcgZz/7wGXepTHjm+3AqcmF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p3acH1LkG6YW/As5HJrKvBM7NXF05mY7k3YoyynEesZckXpqJTAEaguaguBXpJdPK8VSRfEdPSvtLwgjwPnJsXk8VXA70I/miK5GT4yFkNG3T68eqFKfNw5inloMeZVXyP46yeCQqVVrDS2HMBd6p/9F4+XwQ2IBMNN3QUHad+oBcMgBcxmiC91eapxrUg+4/GkKz4A3gBuAq1FBZcQHwFnIHawmjdx/7gc+QS5b5yLOYeWJLm+voBAksw8BGjzJT3rHNI1GxxUugpzXIS2EsJOAxP5AJjAMe6ysE302teWyzA7ndfbKG0KR4PeY3AckDfTJm3VS1bgi5HGqkW+3LbzJvllSwo80rxNd5EpIUf9Nnn6a8U2SP9KD/mF8FO7wE8bWGeamG/2N+04BXo4haR3BeJQqTkci9LuF+dPF7IcQaVTY3Xzm5YLrN43AP8jvM9ygzfRyt7JGomP4N4hDkJQgOir1EfEnHBOQxpiSTT5ciU1S6wipmhF9QbEceHN+Ur5xcMN3mUelApiT1+5SbPo5W9khUTP8GUQnzEvgHxYuRSfiR6STGq7oLyDZkYm2vR9kC4BHcS2ZNMQO5RDrLrIxAnEfsIMhLK5Hzfwve/0dLq860cTgcDofD4XA4HA6HI2v+A3ZN2EuXzy0mAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left ( 1, \\quad \\left [ \\left ( x - 1, \\quad 1\\right ), \\quad \\left ( x^{2} + 1, \\quad 1\\right )\\right ]\\right )$$"
      ],
      "text/plain": [
       "⎛   ⎡            ⎛ 2       ⎞⎤⎞\n",
       "⎝1, ⎣(x - 1, 1), ⎝x  + 1, 1⎠⎦⎠"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor_list(x**3-x**2+x-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "严格上来说，factor()和expand()的输入项不必是多项式。它们将智能的转化任何类型的表达式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs":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glEC6Etk/8AYhAn8TCBulwn4DLtHk8S8dbg6FNyFOzKhTSxM8kg/CBdQ+fWsJ5cmjb2xqDma6T0C2HweR7cs+5NrBHZq0dyL+nj+RC9TfA09S7fQ21Q7ysbkWHo25T/LWtB7C+uetfa7MRYy7rMFyHiL+W8FRwZbm0Ht074s2Fwk3zxWDkdOidQ2UMQT5hltjpUX/f2xoDr1L975oc5FIdZ4X9b9W6OgGvkV+yNyKnNDUy/mIP2Mx0ffSHBVsaA69S/e+aHORcPPc4XA4HA6Hw+FwOByOav4DCNoCMgCDOEIAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin^{2}{\\left (x \\right )} + 2 \\sin{\\left (x \\right )} \\cos{\\left (x \\right )} + \\cos^{2}{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "   2                           2   \n",
       "sin (x) + 2⋅sin(x)⋅cos(x) + cos (x)"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand((cos(x)+sin(x))**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKgAAAAYCAYAAABugbbBAAAABHNCSVQICAgIfAhkiAAABXxJREFUaIHtmm2IVUUYx3+7mrlZrIVGhcWBtsXsxaKQpIJepEJ6o0LyS9ySJOyFEgq0pL5kZW1FURtlsfUlLcVAiBLCtQzMlxLs5UvJbrR70y3bitrM3W4fnjnu3HNmzpxzz5yW3PODy94788yc5/znOTPPzFkoKSkpKTGyDNgB/AYMABuBs8fUo5ISjQ+B25GgPAfYAPwInOBq+BawH5jSwEUDoAZ0NdC2CH9CLkD8WuTFoyODvLq6NM2q+bHACHBdktGFwD/A0pSdRgnwG6B5/dHZAFQRIcY7vnR1aZpF85OR2Lk4yWgTMAi0pPexjqOAmepiPsjrj84cRIDlHvr6v+NLV5emWTRfC3wBTLAZtCNP1avZfCyMIvz5BuglQ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+DfX3EepzyQnIUU0zEnwhWcYnSdeiNPWm+ULkBu6OlA8iO7B1iEAdyJFBDclv9DO5AD8zaJI/s5VPVeLLYLiUXmq51ttIoJxqqU+iQv5z0BHkSOgd4HHgFUTD6OA9pa61D3gJWIXMajXgE+p31FnGB8y6FqlpHs3rmITc6GeR8ruQl/57kafxAPLO9CHguIhtgL8ANfnTpsp+Ac41tAkPhbcZ6lqRRN12muCiQv5XnXORpW4/spT2I0c4txhsb0Vyxd+RFxpfAQ8T3+BkGR+I61qkpnk1j7FMOXO+rw5z4tOfe0meCcYTvnR1aepd88nILnGjrw5z4sufFmS2WpfboyMDH7q6NM2tuemtzjDwOfIPCTuRHdxY4sufM5DcbxX289jxhA9dXZqWmpeUlJSUlJSY+Bf1iiS0GchiIQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(\\sin{\\left (x \\right )} + \\cos{\\left (x \\right )}\\right)^{2}$$"
      ],
      "text/plain": [
       "                 2\n",
       "(sin(x) + cos(x)) "
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(sin(x)**2 + 2*sin(x)*cos(x) + cos(x)**2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.2.3 cellect-合并同类项\n",
    "将多项式中，共同次幂的项合并在一起。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQYAAAAaCAYAAABVVvJoAAAABHNCSVQICAgIfAhkiAAABYhJREFUeJztm22MXUMYx3+729JopeqtCCJRbKRVhPSLTaQkoiKC+lAfaqSNl1SkUuIlxPWhdje1KVoVL+GuICmCoEG1oljqJRZLG6KyiG5Xm131XrZdH5456d3Te+6dmTPnnnuZX3Kye8/MPPOfeeacMzPnORAIBAKeWQR8Dvyij/eBC3JVZMatwEeI5u3Ay8D0XBXVB6FfAl64CJgDnACcCCw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e0vaRdb1MUfpYSi7WdPuBwg/x5+VSRrr02uqfovNFbonXIxt9pjnWDH381yvXUi+g7tFziHCQIog/ZiNiMfPvQWit1KchC+0QkUmwPcG1agfgZaDdrG70kODFGnj5VuLfXRfeXwO/A5brexPfyhijS+auRrqdBpK1T4glnIVOcb4Ej9bm5OvOLtVLnSBbaJyPT0xFgflqBGkW6gXaHLv8xZh825e1ThVt7XXU/pPP8ikzf0378pXD3V959H6cVecMUp5m9AU498cSZSGjtAHB8LC0KmWzzKtMfWWlfo8t+QPk4hgKwv6VNhftAu0KXHUFeM5XTo0ry14NPFfbtTaN7Pns34xZa1JmEws1f9dD3cRYjs5X1SPxEFFK/ResZIBa7Mg15fTFM+QCQc3XBjZlJdicr7c3IU6fSLvCgg16F+42hUEXPKPCWzlsvPlXYtTet7jad/iF+vhtR2PurXvo+znTgAWTTdAfygNmJ3KgKhE/rA/9hXkI2HM/MW0ggEKgPog3HlXkLCQQC+XIscAvwCBJ9+wX+A7cCgUCDcRUySxgGnmFsOHQgEAgEAoFAIBAIBAKBQCBn/gUX8F/YqVLuagAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x^{3} - x^{2} z + 2 x^{2} + x y + x - 3$$"
      ],
      "text/plain": [
       " 3    2        2              \n",
       "x  - x ⋅z + 2⋅x  + x⋅y + x - 3"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=x*y+x-3+2*x**2-z*x**2+x**3\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASEAAAAaCAYAAAD41+rBAAAABHNCSVQICAgIfAhkiAAABxZJREFUeJztnHlsFUUcxz8th2BNEC+EqDEGEBPwvlCJFVAUY/BOMEYWUdR4BESjkBirEQuCUQTBI9FilIgpoqJRCYocjQhEEKL1wlQM0AqCiIpA5fnHb559bPeePViYT/Ly2t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tZCQePlZDEZPS1VRfOTOk6yesM0bzcj+hkOQWMMe7+QHDT2QeNVTyE9j5AW7n12RlclhyO/dfAvcSD59zqsnBsNBzUhk9LMNecq7m3dyg8FgMBgMBoPBYDAYDAaDwaDDf3dQojvH7hBQAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} + x^{2} \\left(- z + 2\\right) + x \\left(y + 1\\right) - 3$$"
      ],
      "text/plain": [
       " 3    2                         \n",
       "x  + x ⋅(-z + 2) + x⋅(y + 1) - 3"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "collected_expr=collect(expr,x)\n",
    "collected_expr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "collect()结合.coeff()方法能够得到指定次幂的系数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEEAAAASCAYAAAAE7bMcAAAABHNCSVQICAgIfAhkiAAAAbJJREFUWIXt1r9r1WAUxvFPawuCg2KLODn4Fzg7lXZwkg511ogOiiCCg5PQuhTRoYJIp6qgnYQO6iT+Ql1EULjQLgoXh6KLKB1UrK1D3gvytklvcl9aKPcLIeEk5zkPJ+97ErpsWwZwGnP4iJ/4gdc4hd6ts7Z5nMEqFnEfk5jB9xB/gJ4tc1eRTG56qGLeMI5a+8b343PQHGsFUy+LN6FA0fEycb0inuEhVqL4F0yH66FWsC9x8Tk8WSd+EgfwPHG9OvwJ5+XNLHpNvgpuq77yMvW2QxF9aATNI4k0S+nBrVDwpnqDKJO2CdeD3uOyh5rK93R83CvQ2YG74ZmrbRqsWvtOm7otzoe8Bez9/0Y8Ez7hVwXhxXVi/ZjFMYxjok2tKeyJYocwKm9oM7r3oV2TOIcbmMcIvlXIrcxOPJJ3/GICvUzn2+FC0GhgX+eWytmFp/LP0tlEmpnOmnAp5L/HYBpLxeyW/yMs43hC3Uz9JlwOue9EMyAm1X/CLA7jLQ7KZ0HMJH4nqrcRJ3AFf/FKPhRjmqoP10J6saR8kn+tqZ2ptxLGN/Czihc1PXXpsp35BzONhKm1Hli+AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$- z + 2$$"
      ],
      "text/plain": [
       "-z + 2"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "collected_expr.coeff(x,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.2.4 cancel-分式化简\n",
    "分式化简函数的名称是cancel，cancel()函数能够将任何有理函数转化为规范的分式形式-$\\frac{p}{q}$，其中p和q是没有共同因子的扩展多项式，并且p和q的系数为整数。\n",
    "\n",
    "一般指在物理化学数学等理工科中把复杂式子化为简单式子的过程 　分式化简称为约分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFYAAAAVCAYAAADcmhk1AAAABHNCSVQICAgIfAhkiAAAAu1JREFUWIXtmD1oFEEUx3+XSLgzwtlIUFQUYzCNUfwAQeVOUgl+kiapVgNpjI1d0milFgpiCsHqFEFDFIUgkTQWKvhVBAKmECUiemIERcWAX2fx3iXruDu72du7U7kfHLfz5j9v33s7uzO7UKOiXATeAo3VDiRGNgAFoLtaAWwEfgJHqhXAHOgABoA7wEekcJcs+utAHlgQ4LcJ+AGcjSHGGUaBD0AqTqdlYgwp5idgguDCblZNf4DfHtVlY4gRgBZktp6Py2EADpJAJuL4LLAaSKiPoMKCXIAXQL1FMwK8C9BYqTPaB5EgBz20o0jg+w17Ashp38mogUTkNvBUzx2WK8ByoN2nPw3sAIaRx0GRkvJ/DHzHe9Fq0xM94fcreVqdRpnlDqXNWDcZws3YdtWd8unv0v5dhj1y/o1IUcctQeXUiaPtfm0P8ufsD4ND5QubVt1Dn/4h4DOQ9OjLESH/FhWNWoJaCkwDk0Cv6m8BDZYxNhwqX1iQHN542JPIQjjkMy5S/luYrb6NE6orAPeA+QH6IpOucWF+uZB+i2QIX9hXyN1pslt9dFnGhsp/nut4Wv+9bgE3U67jbuBLgL7IGWChYVsH7AEuIIV3MxbSbxRSzObrZh/wFbhpGTvn/JcgV+GuRdOJbMfyqj0X5DQAh8o/CuqQHJ4Z9npkizViGRsp/wTyGjvl078TuZrjwCJkP/gNWBPGuQ8OlS9sq+quGfas2nt8xpWU/1V13mzYtyJT/jmwWG0dqr0RxrEPDpUv7AHV9Rr2AWQ71eQxpuT8O1V8yGVrQ15x88AqQ/9I9dvCOPfAobTC7kUWuRyyOheQW7xo89qrXkYWrmWG/SXyzcEklvwbkG3IA203a/s9sNZDX9xs3w9y7INDaYU9hn1nMWno08iiZc6yTao3PzzFmn+fiteHEf9jHMZ7hh1X+8pynjyJfKQYLudJqkAKeI2sIyYTlHd7N8N24Cj/14fuVuTRsaK6YdSo8TfyCyCo8zZDMd8hAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{x + 1}{x}$$"
      ],
      "text/plain": [
       "x + 1\n",
       "─────\n",
       "  x  "
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cancel((x**2+2*x+1)/(x**2+x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHYAAAAgCAYAAADHcIz7AAAABHNCSVQICAgIfAhkiAAABB1JREFUaIHt2muIVVUUwPHfZISVoJRiQWGRmURqREFRxjhED6OX1Af90u39oT5FSQ+C+VIaJZVF0QOaIgIzKKmwQmKgJ9jDgpogInthZWX0xErtw9qXjsdz596ZO+fOveP9w4Zz9l577XXvOmftvfY+dJnwXIuP8Gsqb+PcUep6DPfgZmxM+rbiBRzXtKXFtHKsjuICLMbRmIPb8Q/mj1DPPvgOvXgFl4k/eB6eS20HjYnFu9PK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x1Y5M3STxEOwUX2hsH7HFXerSyKF7M0wTn+Rky0Y8na7bPSftSGapf+heBoO6obg0Gj10L4NBXcd26dKlS5cuXcaZ/wChP3EXY7G6HwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\frac{\\frac{3 x}{2} - 2}{x - 4} + \\frac{1}{x}$$"
      ],
      "text/plain": [
       "3⋅x        \n",
       "─── - 2    \n",
       " 2        1\n",
       "─────── + ─\n",
       " x - 4    x"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=1/x+(3*x/2-2)/(x-4)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFcAAAAmCAYAAACxtgcIAAAABHNCSVQICAgIfAhkiAAAAv9JREFUaIHt2UuoVVUcx/GP11eITUxFB6lQikj3CuLIB4SDfGFRYOhAJBoEKjRp4BMudNUgBHUQhA6uIEROFBQkCJGIGhSkDmogKmrRS68iiu+ug7Wq7bn37LPPPfucs73uLyzOeu21fnvttf97HX6UPBO8jNP4GWfxTlvVDDOmYm7MT8ZVjGufnOHNOUxrt4h20pHIbxQW5FZM32PlEMedj9HC7s2TLfhB0Pc3juO1nOfIykh8jEu4F397MGqwzm9hBWZiFnbiIbrqnPQlIe4uGJLkdL7Ce8KCduIo/sCEJsxVi63owyrMwJuxvCPrAH34IOZX4z6mJ9r34TwmxfJYfIN1DYiuh/F4LNzgv2TRmQcn0FtRdyjWpzISa/FA2CEwAj/iQCx/hD/xSqL9C3Q3ILhepqIfCxN1tXTmxVZcwexYniOEwQ3VLujEbTzCDSFMJHlDCBWbhbg3P9G2CP/gTCJ1ai5f4idhM2TVmRcd2C3c80PhIfekXTAGr0Yxu3HNwA/Gd8LiL2tAWHcUk5ZerzHGp/g96h2MLDob0fGusHPXCJtonRBG36+h+z++xsFEeQnuCE9rXtZBBmGi8DqlpbQz8h7hVZ9TpT2rzkZ0XMWHFXXbcSFlvqc4hcMxPxc3sR7HcDLrIDmzX/rCtkrndWyqqNuiyuJ+gsXCsaLT//FkufDl/Q3bYt+u2LY4b8U1+EyIoUswJZHGx/ZW6uzFr8J/gRl4Wzh776nW+bJwjPlLCAlLhTPkL/i8ov8RfJu75HSqxcVurdf5IvYKa3YXF7ELLzRhrpKSkpKSGoyIv/1tVVHSFEr3oomU7kULGVbuRUftLqnk6Qw0y72oyzEoEnk5A810Lxp2DIpCpTNQBPcii2PQKveiISqdgSK4F1kcg1a5Fw0xmDPQbvciq2PQCvdiyKQ5A+10L+pxDPLQmTtpzkC73YusjkFeOnMlzRkognuRxTEogs4BpDkDRXEveqU7BkXROYBqsW+/4rgXaY5BkVyWkpKSkpKSkueOJ0R2HtVCXwDMAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{3 x^{2} - 2 x - 8}{2 x^{2} - 8 x}$$"
      ],
      "text/plain": [
       "   2          \n",
       "3⋅x  - 2⋅x - 8\n",
       "──────────────\n",
       "     2        \n",
       "  2⋅x  - 8⋅x  "
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cancel(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAN8AAAAoCAYAAAB+bi+NAAAABHNCSVQICAgIfAhkiAAABB9JREFUeJztnEmMDUEYx38ziG0cjP2AA0HsESdbnjmIAxfLUURcHUQcMMHcRTCGRFw6LrYIiYOIAxERCYnlgAQX+xZBONgdqofW3uuq7uqlut/3SzozXe911f/7/lPd1d2TDwRBKD1jgUvAXeA2sKJQNdXFhTy7oMF1cs3RGGCW//tI4AkwKMsBmxQX8uyCBtcpNEd3gHF5DdbEuJBnFzS4zn85as1ooLlAP9RsT5OtwHXgI/AGOAtMT3mMMpFVnl3QUCWvc/NpGGqdOy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GzX5Nvu/y8t8oZLEKe6UNTXq3yN6OesQBEEQBEEQBEEQBEEQhHT5DQB08fQX3qFJAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{x y^{2} - 2 x y z + x z^{2} + y^{2} - 2 y z + z^{2}}{x^{2} - 1}$$"
      ],
      "text/plain": [
       "   2                2    2            2\n",
       "x⋅y  - 2⋅x⋅y⋅z + x⋅z  + y  - 2⋅y⋅z + z \n",
       "───────────────────────────────────────\n",
       "                  2                    \n",
       "                 x  - 1                "
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = (x*y**2 - 2*x*y*z + x*z**2 + y**2 - 2*y*z + z**2)/(x**2 - 1)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFwAAAAmCAYAAABJVvz/AAAABHNCSVQICAgIfAhkiAAAAw5JREFUaIHt2jusFFUcx/HPvUpAvRZeQKRQCo0a5VVYIZgLhbHQxkdJiL2FIRTKjXJ7QnhqQmi2UzFGEwpDLCTEGBNNfBRqIjSg4CtGiQ2iQvEf4rjMzmN3lt17Od/kZOecmfn/f/vfc/4ze84hMbbcjRP4Gl/i6ZGqGU9ajdFKrMuO78RZ3DqIwQXIUGP0Fe5py9gC5ZoYTfZp6BEsEr9gm7yMT3EBv+AYVrfs43rRWoyWihy1YVBDBRzH8yLIa/AufsT0EHx108FcS7Zqxeh7bO9qW4+LeCirL8ZJbG1JWBVT+AdPZfU6Gl/C5YKyq8JXR72AV9mvHaO38UZX24c4lB1PZOfriGqLleLLPJrVqzTC7bgrV/bhPO6r8NVR77uV2W8Uo+04las/g9/E8ICN+Bdf5MqaOoYH4C18jptqauxmJ87hgRq+Opp3pm77jWK0QfSmaTEsTuPFhgII0UVDLl9matjZ7dqe2UTjLH7A/T3O78SfuXIJf3W1bSrRV2W/ksUiFz4u8tS34inblGV4sKJUvZvuwU/+y8tNNb4i3g7K0sh0dv5qeQcHutpu6XFvHfu1+AQHxWvZk4Ma65MDioN9lSqNr+IM7m3ot6NeSunXfiF7RQ463oaxPnhdBHKL/z+YpnLXlGmcxa8i9eTvX1LDd0d1wAexX8g2/I2H+zUwIL1y/lzuml4aJ/BHj/s31/DdUR7wQe0X8gFe6/fm68R80FjKJFaIp/Z53DFaOYXMB421mRE58RvD+bveBjPGX2MikUgkFjgT2eflkapIJBLNeUws0Z0TI/jZ0coJ+l3TnA/cJrYqvDBqIePAc2KadVWubT++w/Ih+BubHj4qJvAZjmT1HWJKtpUpzwJu+IATiwiXxELCBbGtYFikgGd8LKZanyi5Zs7gS3ZjE/CbR+h7i9gWNomfS647hDcrbJ1pS9RCZR1+F4sJ7+H9Ifsbmx4+ClaJ1e7ZrL5WTL2WrZD3w5TYJLReBHxHdnxD7YecFnPah7vaj+Kjln3NKM73nZb9JBKJRCKRGAZXACLz4Zb96OOzAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{y^{2} - 2 y z + z^{2}}{x - 1}$$"
      ],
      "text/plain": [
       " 2            2\n",
       "y  - 2⋅y⋅z + z \n",
       "───────────────\n",
       "     x - 1     "
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cancel(expr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "既然factor()会完全分解表达式的分子和分母，它也可以用来做同样的事情："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADUAAAAmCAYAAABkpNNFAAAABHNCSVQICAgIfAhkiAAAAqJJREFUWIXt2DmMjVEUwPHfIMEgYsZaMIUtscxMZAqZWIYChcpSikY0RGQyxcQE0ysQFCISNCMoiEJQEEEUJIiQWBprLBF01lHch2++99735q22909u3r3nu/ecc7+7vO8cqvwRTMRF3MUtrPit3pSICWhK1cfiCWqTBozCS0wur195cQLtCc9vY1KSgh04XEqPSkAj3mJkhmctuIeabINr8Q7zy+JacdzAhpisXjhXrUkDVwtvJDrrp9KXvhkfMaMoN3/Rid4MZXukz3ZcibQH4xLW5FK+G+djsuPoickuYG8+XudgBMZHyi68wJRIn2X4hKHCS+9Bd3+Un5J+ntrxMNJeKaxmfd6u948teI7pMXmjsHqTMQ/fcDNSZmdTeBb7Y7LWlLI6YckfYXOW8d0yb6NoaUuYUBeeYVqGZ1NT42cljP/JoEj9jXClR7khLHsL5uAz9mXRtRdHc9h7nEW+FeuxUN+d8YO61O/rHPrT6MCdDPJr2IMPWJ6v0n6wTZhs0n/jOmEV82Y2vmJ0TL5T2MNnC1Gagy5hh7Tqe1kMifU7goOFGrmKjTHZWnzBzEKVZqEG72U+e4si/YYKu2RuoYaW4j4GRmTnZT9HlWAjzhWrZBMaME64Yl9Iv0AqyXrpV3xBtAnn6J4cnyFVqlT59/kRZvT+Vi+q/H0swGkh/OjFqkKUDCilRyVgmJD2in+qlY3VQhjfEJHtxgOMKYO9glcqH2pwHQdS7Q7lTadVZFKwRAgUO4Uv55Yy2qrYpAjhyRchGZKNbsWF9hQxqUG5u/RhsZDyHYBXCf2KCe0rSpOQ7FyLkzhTZntl334NQo6gK9VuFEKTUmdzhwvJ0mZhUh2pemKuvBDqhLgqnj47hsslttUm8/k7VGI7VapU+d/5DpmYmqtZJyI/AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{\\left(y - z\\right)^{2}}{x - 1}$$"
      ],
      "text/plain": [
       "       2\n",
       "(y - z) \n",
       "────────\n",
       " x - 1  "
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(expr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果您只想确保表达式处于分式化简，cancel()则效率更高factor()。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.2.5 apart -分式裂项\n",
    "分式裂项函数的名称是apart，它能将一个分式分解为几个分式的和、差。且分解出来的分式，都是最简形式。\n",
    "\n",
    "裂项法，这是分解与组合思想在数列求和中的具体应用。是将数列中的每项（通项）分解，然后重新组合，使之能消去一些项，最终达到求和的目的。 通项分解（裂项）倍数的关系。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJwAAAAmCAYAAAAx6fJeAAAABHNCSVQICAgIfAhkiAAABWdJREFUeJzt3Hvo3XMcx/HHb9gwjLnkEiMrkjtF2PxaI4oSFn9YlJbCX1phbr+/SC7ZYpjUQZi1RbmVmJ/bmEsYubaI3GuWkMv4+eP9/fX7Or9z+Zxzvmfn/Nb3WZ/O93y+t9f7+/7cv+9zKCmZwKzB+/gQ1/dYSyfsi2F8JOw5u6dqSuqyU/a5FV7HkT3U0gl74Yhsew98je17J2fLYVLB1/sl+5ycpYnKd6Jlgx/xM3brnZwth3oFbhFGcGcb11wrnPQ83mtTVz2uxluiYP+EJ3Fo1TGzs/xvhQ3ndnjPY7GNaOWKJFXnpfgCf+AdzCpYRwopWlN8U7PAHY8FWNemuOOwj+hOx92wDhUMJRw3iKU4AXOwSRTs6bljporW6fLEezdiVzyIi8WDbkZFmh2k6TwPi3EjjsJreBb7Jd6jERXFah3U3DfjmIb12QnD/t/CzcOfmJHLW4zPsXuNa12JhY1ulqMi3fg8O+AfnFlnf73amGLLFLyM+S3oqWjPjno61+K+qrzPcVO23apP8lQUq7Wamr6pbuGWYSVW17jASnyAa7PvC3E+ThNN6DRjRm6LU/FJgrBO2FHYsKHF85rZMiAcshoPFSG0DSbjGDxXlf+caEVobkcvqembrXPbCzBT/Ro9IsZ2T4tWcJFoCddn+3fBKjHemYQVeKoY7XW5Q4wT32jxvGa2nCi6s3U4K8ubL5y7udhNzPZ/qMr/AXOz7WZ29JKGvjlI1IiDc3nDak8a1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pKSkpKSkpKekh/wHJqk2gKxSnVgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\frac{4 x^{3} + 21 x^{2} + 10 x + 12}{x^{4} + 5 x^{3} + 5 x^{2} + 4 x}$$"
      ],
      "text/plain": [
       "   3       2            \n",
       "4⋅x  + 21⋅x  + 10⋅x + 12\n",
       "────────────────────────\n",
       "  4      3      2       \n",
       " x  + 5⋅x  + 5⋅x  + 4⋅x "
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr = (4*x**3 + 21*x**2 + 10*x + 12)/(x**4 + 5*x**3 + 5*x**2 + 4*x)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL4AAAAhCAYAAABnRBELAAAABHNCSVQICAgIfAhkiAAABZFJREFUeJztm2toHUUUgL+kolUDrWm1FqxBLBilmiAVRKPcXkR8UCWiYPvHhWJ/iD9E8kNr1fypaZGgthq1gm5FlGp9gI8UtVKolULFJioWH7WB0saYUqu1vhq9/jhzcbL37t59zO7d650PBu7O3jnnDHt2dubMHLBYLJG4H9gN/AJMAm8Di+pgx9VK9yGgBNxaBxuyphn7bJTWBG0LwBBwBVAEpoAPgfbkZkXidGAUuDtjvfWkGfucW9qAv4GlWt1twJ9Ah1b3BPAtcGYKNjTj6NeMfc4V85GHcKVW1wJ8CjynrvuACeD8lGxoRidoxj7nis3AHmCGp/5a4ARwH7IeWJyiDc3oBI3a53XANuAA8DtwBPGfh4E5NdrOQ2YX69M0MAyPAuPAQp/7nyBrgOsCZPQjDzGoFGrY0ahOkIRG7fNfwC7geWAtsAEJlpSAg8CCgLYr1f+WpGxjIIPI9OUin/tF4DjwD3BpgJy5QGeNcloNWxrVCZJQzz47hBuQqjHTp36NkjkU0HYYOEzl7CIz1hPs9F3AUeAO4C3E4DSxjp8tDvEd348uJfMDn/uzkI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bDChJw+OnyRnwaX2yz4biaLoZTfwsvrdiAGKxHjP6hSRB9EK/BhT5jPI8eMy65Bz+Xp+5MGA9mFtSKonD3QA7yGpm5uQrfoR5IWtFrOOw1FVdI4jOa5fGtLRcOiO34Us+O5CVtFrgOtjyDyiSplj6vq7EG2j2JBETx5oR47MvoP0E2RvZAsSPOipk11NRQfpZUu5hJt7J7UhrJ68ZC9Z6kza2VIutR3ShA1h9EB+spcsFovFYrFYLBaLxWKIfwHGqC+bvjctCwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\frac{2 x - 1}{x^{2} + x + 1} - \\frac{1}{x + 4} + \\frac{3}{x}$$"
      ],
      "text/plain": [
       " 2⋅x - 1       1     3\n",
       "────────── - ───── + ─\n",
       " 2           x + 4   x\n",
       "x  + x + 1            "
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "apart(expr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.3 三角函数简化\n",
    "SymPy遵循Python的反三角函数的命名约定，即将函数附加a到函数名称的前面。例如，调用反余弦为acos()。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAVCAYAAADhCHhTAAAABHNCSVQICAgIfAhkiAAAA9tJREFUWIXt112IlVUUBuBHJXVSMcmhH8ouUjGIzIwoSBSULqoLiSgsSM3L7MabSAgqSEVKukqQRCsqNct+iEooCPsZnUhEqBQsrWxKTStNrZlxuljrcL455ztzJE+g5AuHw15r7Xf/vXut/XEe/zu8iAMYcQYcU9GHBS2Z0VmIG3EKi1rAtQldGNkCrrMOm/Eb2lrAdZNQ1eIWcJ1VmCjUtKqFnF9jH4ZUDINLgu7Dy9iNoziCTswfgHgG1uNH/CWk+wFm18QNwjx8jF9xAtsxtwHvNLyBPTgpctA2LCnEPJi86xtwbBYKuatkLmvTt6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"text/plain": [
       "acos(x)"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acos(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAMJJREFUKJHVziFPgmEUxfEfsBHoBjeaBJJ8AWkkI7PY2Kh+Ar6AFrObyUojMrqbG5ENG6PpRoCkm06h3Hdj7MWHYOGm557z/O85/OOMsEZ7Ry/gKby7fXADP5iitKXfB/iYSs8SOrH3Yu+jmIKr+MQcNwEOUU6B2dwGtMYzKnmf9tVYbL27+Dg09Rq/eIvkh0PBS3xhghO84hv1FHgR9WY4De0q0gd/gQ2sourZjjeOA808sIZ3LHGe47cCfklVP5LZAJRWKsLu3YOtAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x$$"
      ],
      "text/plain": [
       "x"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cos(acos(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAUCAYAAADskT9PAAAABHNCSVQICAgIfAhkiAAAAcZJREFUSInt1E2ITlEcBvAfMzFJTShja6GUjciSGgsWGhE1ZWMxmkgJiVIKiY2aMotZKKOkFJksNAsb5WNlMUxjShZIiixMRPK5OP+3bmfue+/ra0Geerv3fe7zf85zPv6HfwRd+IIzWIAdGMFjfMAUbqMPM/9EgH58Qzd2xvsLXMQpnMOb4K9gxu8OMIrXaMNa9Jg+00V4FiG2lJlsiI+t/JYX6jrxEcMtBD0c9YMNor3wcQpD2IUJaakaWIpeaR9v4EEWfBauthDgUzw/NxNsjoQnMv5g8H0lNZfxDh01g7djPHzWNxMdC8HWjL8U/MqM78DbCFGH0+FxvUp0LURLMv6RtHyzM35j6LfVDL4ndJOYXyV8Ks2o2CZz8VVavhzD0gHsrPDcHYNPSJ3QFPNCeCfjVwd/IePbpNYbrfDcG7XjWFgmKPZqo7XuZ5oV8RzL+DXSrTfSZPBDGIi6bryqCAr2Rdr+jD8b/LqMH5Su364SryNRc0/NnhfvgWYr0DBYhod4Hv834S5eZvrtOB7hbkkHMMcTnM/JsSiak/G90l6/x4HgVkkz3F9iflT9TXqzpO6HcDKMFv+q0c9i0vRD+R9/J74D8kV7AFK4faYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{\\pi}{2}$$"
      ],
      "text/plain": [
       "π\n",
       "─\n",
       "2"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asin(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.3.1 trigsimp-三角化简\n",
    "由三角函数组成的表达式，可以使用trigsimp函数来化简。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(sin(x)**2+cos(x)**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSU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4MPvpHean6zyd/rIgtSFUWRzcEoAPkjwR5P41QbUC8GDKxQfs4xzJxg6fZTl6rHLo78LKYRzkS0qwDPIrmOWGvOgGrQZqYealdejR1sqzgJeB74DFvjY6IV9xvkM4C8ffo5hk4ObgX/wz0T3ITXhDuBapNwIgmXET0yAS4EpwKtI8JnYHlBvMgjdx2Qz13ke/bbMZWIkMAlZXg8DvxCrxc5U2S0eckFn8zKL/B1IUd+lnBc97HMwTPk7jbZMZJJs9JF1Jk8r9jozWURI3bI4ID4GrblW4v15JA97zeWFl4l/N5KBfPLZZ+Hm6Ni235eqp0mvb3PJTkJmYiuyHLchm5dEE6lAda4x2krxrjcdPKqcr4jfrPQHEVIXXAPio7lbLLT0O7vFK1Xxj8TXTZnAOu173CV7PfFLsANnd3mD0VZP4prOhiq8a66rkOWvHThD28qVvy6BzgrlzDbaapDJM8ZDZoHKNBO8xgqCCKkLrtB8NB/4DqQmWo5EZAPy8m0U8q2vG4nqbUhBPRf4GgmGg0iAXIQsaYtd46wC/ta+DiRDjQfGIcvsJoO7BslkE5HvV/3BJcA7yIveCcTqxHrk5kxRO5osstchN7nBaHPe//1s4U8ntpNtQmpLNzpIrgAPA1P1B7FXR8WGHfuBh138AfOxGHnAe5GlZA+yZS938W5HgqUbCZxvkIxlK8ZnIh8725EscgAJ4LnASS7ucGT7/5mXgRZU0Ttz5ameX4GLLTJlKmN7WZuLFPJmZhunfK+P6Y4NiX4f+7tiRYS+Zy4/uzoM7mD6mDLMQwy9bJDGv1/HH2+0VWvbuYNiUWowFHwkG9l1rh+EsXOQbF3vam9jYLb9RxOGgo8AXA08Qer/LFiApP9zUjxuGmmkkUYag47/AYX46LcTI9baAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{\\cos{\\left (4 x \\right )}}{2} + \\frac{1}{2}$$"
      ],
      "text/plain": [
       "cos(4⋅x)   1\n",
       "──────── + ─\n",
       "   2       2"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEIAAAAYCAYAAABOQSt5AAAABHNCSVQICAgIfAhkiAAAAzFJREFUWIXt10uIHVUQBuAv0TzGKFExoqLQYAwq0SAGUdSFD4wEFdGVK5WAiBoXWQgJiK40qKPgQsEHRDcaGIkQEB2QqESIidGFEFeKkZgxjo9B0FEz8bqoc5menj59J/fOI8L80HR3VZ2q6jp1qqqZx5xjM/bhdwxjJ1bPqUdzhA9wv/j4y7ADP+LMuXTqeFCghW3TrPdUHMPtDTJv4ics69LGlcL3DV2un4DCzATi3KT32gx/Lf7Fph7t7MCQCHxPWISLhePTie34Eidl+IMYQV+Pdq4SAd/So54ZwbNil1Zm+KtENrwyTfa+xkH5oLsDHyan/sZhfIyHSjKFyUejTCvwNn7GX/gctzU41Y8juLRBZmvSf1OGP5j4d1XoC5JPraSjjScSbV2dsgcSc0hE/im8hr2izbVRyAdilyhme/AC3hDBOIYbamy+qHMQiGCOyRfJNcnGARN3uT/5Vc2kmxP9uTpl+0UWnF3DO6v0XMgHoiWiXca6RH+vQn9JzBA34pzSVS1iy0QQvqpzuoRtyc596X1Let+OhRXZ5Ym3t07RfvyBMzoYLOQD8Z36c3dQHJUyWpnryYrcqkQf7ODX+RhNPjyS1ryPxRn5UTG3TMKmtPiwSOs7saJGrpAPxLsZo7tF6naDa4zvbCc8bTygn+KUBtkfRKZhYso8j3vxPR4V/faIOPdrp+j0SIY+ZnJ6ThWj6b50CrLDpecN+LNBtq+kO4vTsR6vip38xXjtKDR3jTp8lPjd4Ly0dncHuXtEix1K8i83yC5Mst8cjyOvJ8V3p/fC7AZigehEww0y6/GPKKgrxJxwVAx+dbgk+fNOm1BO11txcs2idiY0pdlMooVPROeqG7iuwwAO4RYRsMfFt2ytkYer031XHXNEVNEB0V/7RXtpiT6+KMkVZjcjiLRv4eEKfU3yewgXVnj70prra/S9JerWBXXGHhQF8lux+7+K2f8xnFaSK8x+IBaLTfqsRFuZaL/h8po17aFpT4W+XBTJXIc74bFZfNgVPerZKJ8p/wssFYPZzh509Ik5aaDKyP59nYAYwxdYImrW0S50XCR+I56Rn3nmMY95jOM/JSrm4MqGXIgAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin^{2}{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "   2   \n",
       "sin (x)"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(sin(x)*tan(x)/sec(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "trigsimp() 也适用于双曲线三角函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFcAAAAVCAYAAAAzWHILAAAABHNCSVQICAgIfAhkiAAABENJREFUWIXt2G2olFUQB/CfaaZZaC9GhdVCJmWQRSIUBRVCJRVRIfml7EWRtCihQiPyS1qm+CHCKAsLIi3FQgoRqlsZmF4rMPNDZirYtSwzpMzX24c5y9373PPsejc1JP+w7O7858zMnjNnZp7lOP43qKAd85tc/yZ+Qb/DFM+h4EoR8wNH0WdTqGh+c4fjICYX5GfgQSzBBuzGH1ghNuSE5kLthCVowymHwdYRQ0Xzm7scO9G3IJ+QbP6EtzADryfddixCj6ai7cCIZGvqv7RzRFHR3OYOEVn7Soa7AbfqmqFnY0vyd2c3/eWwHpvRsyrIXYkRWIit2CPSfTlGF/RG4zNxxXZjLabgpBLnt+GjZG+PyKRP8VCJfgUL8Cv+RituKdG9X2Tfwgz3MZaKza/FNrycPl9X4JaLTb+jIO8hDr4dzxW4BTgfI0tiNA77xY9/F9MxD9+gpUZvenKwHXPxAr5NshacWLA7PnFtIruqdldhdY1eJel9IhrTSszBG2KDD+D6TNytKe7uNrLHk785Bfmw5Os7NZmI2Uk/d0NGJm5WztFQ7MMOXJrhB6X3q5KRLeJqVdFLZEiu9qwRB3ZWxu6ZNZ8raX07nino3ZjkHxbk/cTGrs3YrodeaU17sl3E/MSNTd+npu8L5W98/8Svyjl7MZGPNQjq1aQ3PsMNESe+sSBfgz9xWgPblWR7k84ZU8VmUSaKPtvFVe4OZqV1H5Twg0S524RJSXcZetexuVuUmy5YnQxc3CCoNUlvcAm/OfEDamSTdXTsObgdAzNrK0nvvRLbK8Th1aJ6k3L1tgyPpDXrcXodvRk6btIXOLmB3a3iFnXB98nIqQ0MbEh6ZfVtZeIvKMjvSdyBxB8UtXV4jU5F/WmhJfG1uDzJ3m8QdxUTk/46nctaDtWkOJSkI0rqrhzR3cy9sITPZW4tBmCUKC8H8JuOWlzR/c09N8lWNIgbHk26a+Xrfy3GiARoS2vmNtA/Ien/kCMPtebOU/64N1i+5pbhNZ3nzIrub24PMVlsb+DrybT2a52baA6jsFccwkBRPvapn3iXJPuLc2TttDA0w1enhauTkR91rps9Ra1sx1OFtTeJ7lxEdbq4OX2v6P7mEk9Z9frA04lvVb/GwjX4SyTIOUl2l/q9AO5LOpPKFMaJzNuDd/CsGLRbRX2s4vlk6Ge8hJk6xprPde2oO0UXXSS69GwxslR/cHUurmhuc8ck+cQMd2/i9otmOi3zGpt0h6VY23Qte9WyeW1JbG8nH+eV8Ijuu1hctb2iwy8Tp1eLu0Wd2yUG/HUiY/tkbE4Qf25sFFmxQ1zPJ3RuoBXNbW5vcXhfZrhpOppS2atFZP02/I7LMnaqDwkrM1x/MYbVy+xjGlPEj7/iP/D9sPpZfcyjj5hUlh5lv33F7V5UJHJPQccq9uMr8cdRq2jORwMXiR41U9Tr4ziOYxz/ALRdUEG1nyLSAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\cosh{\\left (2 x \\right )}$$"
      ],
      "text/plain": [
       "cosh(2⋅x)"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(cosh(x)**2 + sinh(x)**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAVCAYAAADhCHhTAAAABHNCSVQICAgIfAhkiAAAA7VJREFUWIXt11+IVVUUBvDfaJmThRNkVFgcaJIySCIRinoIhEoiokLyqT+iRFmQD4H20FNWlvUQYZSB9ZLWSIEQIoRTGZjOVGB/npqcQCebMiNqGh27Pax9mzNnzrnT3KuBMd/LuWetb397n73XXmtdpnBaIkMNm5sc/yZ+xKwmx1+b5l/e5Pj/DJnmN2oh/sLqFtfwLgZwTos6pxSZ5jdqJ46ivcU1LEprWNuizilFprmNmiei6dWTtI5v0I/pdcO0EtIibMVBDIsw3ImlBd5SfIRfMYT9WIOzKia/HR8kvWEcwod4qIKfYQt+wp/owW0V3AfQltZdhp3iAO4s2NvEodTwTM6+BZdicYWeFRhJH/IO1mETvkB3jrcuiQ9iI57Dl8nWjTMLuiuTb0Ccel13L/bleFni7RJJeQ9exBtis07gppJ196R1VyXxBWns13JRgg1pvmIkLk7258vE5uM4juCqEv/c9LwuiXyPC3P+M7Bd+f3uFZt/QYnu+bnfWRpfw5MF3s3J/n7BPkts0v4S7Tw2p/H3pfe16X2r8TdrdvLtLRN6KTkfm2DC1xJvZYlvnji5voK9F7/jvAm0s6R9wNiTr6NfXMXinDVxvRphrkgRB7AqjdmBGRX8IfxQ5tiXBl8xwYS9iddZ4e9P/o6cbXWyHRJX6Q7MKRmbJd57Fdq7xUHkUY/wqvyUx9NGI/YTnN2Ae1BEKsaGXEeO0Aiz03Ogwj9Q4MELuFdc10dFr3JY5KKFJRpHK7RHjL8mQ+k5s3rJ/2Aw93s5/mjAbc9pj8FkI+qyCn9ZROXRgSXiCp/Az0ZzV6Zxe9Cd/HlcnGy7J1j3MtFCDCT+xgbcaYn7bZnz3+aoTarb/E7lOaoKryetu9J7ZvIb1SYq5OA49iiW4JhI+HNEn3RcdVBcmebZVubMV735Jf561bs+iXxnbJ6ZLnJLDU8Uxt4iqmIR9Sp5a3rPTH6joEt13rxBXLE+XJRsd2ucC+9P/lUVfitERAzjbTyFV0SfsivHezYJHcbLWC9Oq4aPja8kR0UF6RK9yQZRemtJu953ZZrbqGXJ/nDBviDNPWB8qqinmhtL9N4S+fCSinUgqsg2Ec7HRKXaIU4hj3tEXvhNNINfiUgqS6oPigTeJ073CD7H4zg3x8s0t1EzxEF8mrN1JtsvuLpkTL2p3FOwzxZJvCraTnusER9+TYs6j6iOtP8FZoqKu70FjXZxg7qKjrLu93TFCD4Tf8p7RGGaLC4X+Xm96l5uClM4CfgbS74VlWwtoeMAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\cosh{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "cosh(x)"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(sinh(x)/tanh(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "与simplify相似的是，trigsimp对输入的表达式应用多种三角变换公式，使用启发式的方法来返回“最好”的那一个。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.3.2 expand_trig-三角展开\n",
    "要展开三角函数，可以使用expand_trig函数，它能够使用三角恒等式，将三角表达式展开。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQQAAAAXCAYAAADtPTGLAAAABHNCSVQICAgIfAhkiAAABnNJREFUeJztm22oVEUYx3/XtzQLFTRSLA5kZgVZVFqQUCAVEhWVUn2oJVPKXsikQFP6lJVZFr3Yi8WtL2lqRUKIFHpNya7XEszqS3KtbDVLjSi7em378DynnXt2zjlzd+esa3t+cNm78/LM/J95ZnZmzi7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/QMSoALgRvUfmckb3uCLR8xA/7jxpcPs4wZ8Bs3IT7mSgVDgSnINugY8Bvlc05A8m2xjQ2abzJK0zal9OU25HFLUcsvTSnfR8t/H0mvZrU/KybfttqHJPnORfMwpP9t+v4TtXNRQp04za4UqP2xY5JuqG/c+PJhvWIGao8b8DdXEnlTjd+s7wP8DGwLcrO8v6J0mSnAEeQyZQTy3PQoyQN0rra1OpLem/PgMi1r+2rnGOznQRtR37loBtiJnC1v1/qvpJSP0+xKgdoXBJOobqhv3IAfHx6PmIHq4sbLXDG3Y9fS8wgREq5SaVuP3lJCntcOx37uugJYBfwEXI04Y4H2Mfo81eQyfV0fSV+KbEEXILfHUcwb47f0dT49z3R9kUc0fZBBC3H1XZrmkE3I2e81ZEs5P6EsxGvOmnrHDNTXh1nGDPiLG99zBZBzzV41vBh5ftmunemg/Aw1wM9KD7LFKQH3RdLHa3+KVG7Bwm3cpJi23kUG8QxL3gxkpe4C3gOeAF5F9EWdEl5C7QNeBhYhq28J+IyeN7euvkvSbHIH5YuhuxPKhSRpdqFAdTuE3ugOyD5uTHz5MKuYAT9xk9Vc4R7kBw+7kJXpAPAV8ChwqlEuwN/ADkAc8oWRNkbTDlL55REof5liiyVvCHJBEndrDXJjuxrZgh1BbnjXArdYyt6KfNL8gXxRZifwGJWXO66+A7vmKJMQje3IdjEJF81pFKhuQeiN7oBs4yaKTx9mETNQe9xkPVeOC3ORTidd+LjyAMkrYqOQpvkj5FPpUgdbJ4pm3zSjD5tirgxEbmDX1GhnELJyr6q5R9mTpDm8BHvJwc6JpNk3zejDzOdKI/yyqxv4EvnxRwdyM1oNZyPnvEXEP9duFKKaRwL3AnciX+H9DvmRTJovTiTNvmlGHzbjXGlKwh+5HEQurkYlF8+xkPswJycnJycnJycnJycnW/4FanaGjGT1vnIAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (x \\right )} \\cos{\\left (y \\right )} + \\sin{\\left (y \\right )} \\cos{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "sin(x)⋅cos(y) + sin(y)⋅cos(x)"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_trig(sin(x+y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFkAAAAlCAYAAAAp60UVAAAABHNCSVQICAgIfAhkiAAABDpJREFUaIHt2VuIVVUcx/HPVGSmEaldJEqjEoq8EBFRauZD2UMPXYyigiAkiHmKHqqH8qELIT0oYkYRpwi6EnQh0oSGMgsKpkwUKksSDS+NVNLFS9PDfx/Onj3nnL33dLYz2vnCYs7e67/2+u+1/2v916wfXbqMgNOwC+eXaPMm7q/GnWp4CF/gN+zBu7gkVd+HlRX2vwwvlmwzCwM4tfPucFwFz1yAVbgSC3EI6zCpgr6ynIwleL5ku434EXd23KMjxEQcxg2oYTBTpid2i/AJ9iVlLS5OPadPfLwnsRe7RdSmA2WxiMiejA+L8Tempe4tx3c4Pbl+FJ+O4P3GBFPFYF4lpuMGvICzknJ8YndzUi4U0/cN/IBxSX0ffsXjmIHbxCy5PdXXcnzYxIcefInnkusHDF+3F+EAxo/kJUeb19CvMZh9iq3JE8QMmJtq93nGZp3GwMHbWq/H1+IgHhT54rJM/SwRDGUSZiGqWJPTLMN8MV0P59ieh5exVQzCLuHfuSmbrzNtduDM1PVJ+KvF89eKhPwYbhWRnebP5G/HI/mETj8wxdMikVyD7wvYv4eduFcM3iFsxokpm4OZNoOGBspesYVrxkLMTux3N6mvJ+Y9BXwtRVWRvEJjgDdn6g5oLB11Josk94RYArbgFOWDoN/QZFlnNt7CfXhHrOtZZoqPvKtkn7lUMcircLdISAMaCW5iUr8Nl4tdxZTEh30iCpfgAlyN1SKay7AGFyXPrTMN72vsnx/BdZiXaTsfH5Tsb9TIbtHqZWlSPwOf4Q9Dt3ALsUmsqZvEQOwXH4zmCbMmlpk0G9Cb/J4kZsWzGZvXsT51PV7kgSty364L4uN8a/iS1I5ekRgroYwjRwtbxb74Z7GvLsIcPINfqnKqS5cuXQpQP0gZHFUvunQ51jhH7Ic3i3OKm0bVm2OUqeJfYDgD28VBfJcK2WjoKRz/Ew2P6nU64rx3i+Eqx1jS8OYLDXOn2Dzc0syo6vPkkTIZL+EeQ3c+R0rDq2mctbRjgsgdvXmGZampVqcbh49xV5O+m2l4RfQ7yml4NcUGOU3LSB4JVep0PXhF6xdspuEV0e8op+HV2vjQio4OMtXpdHPxD75KlZkp21YaXp5+RzkNr6aDg5yepku1PguulwU5Hf1XnW59Yj8nVb5J2bbS8PL0O9preA+Ls+t6uaPJvewhf2HS8s5KvJpj/1NOfSd0una00vDy9Dvaa3irxUF+naeE/ytS93YU9HEY6UHem5QitNPpevFRcu9SnRVr+zWUkjpp/e5Gsd5f36RtOw1vICl1fk+uiwjAuYx0ALZp6HT7E4fSOt12nC12DmV1unasEVE2Jekrq9/1i3V8ntjlpKlCw5soNMk608USNyB/1udStU7XjrqGV1S/o7yGV1Ms8S3QPHfVCvYzZhlzGl4eR6PG19XwunTpcqzyL/hgR6PqgX/0AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{2 \\tan{\\left (x \\right )}}{- \\tan^{2}{\\left (x \\right )} + 1}$$"
      ],
      "text/plain": [
       "   2⋅tan(x)  \n",
       "─────────────\n",
       "     2       \n",
       "- tan (x) + 1"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_trig(tan(2*x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "expand_trig()与trigsimp()相对立。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF0AAAAXCAYAAABpskPJAAAABHNCSVQICAgIfAhkiAAAA9NJREFUaIHt2VuIVHUcB/DPWoqbhQoa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dNOymPeLF7QfCOq+jd8grtxXEauonNJnyFu9McZ2qJEO2DkgwaNh43tBb7KUNVe0pdr7N1dJbKzxQAt2uomDPeKH3G4YTSZ8LYYnme3IHub9k7lEcNM8fD0zkQH0gLqw/OpFmS7xTNPzxGNqA1cIF4fTMZ/YizEPWJ9PojPtfZwtgQPitY7hVGi/iLwAF41/BXAFKYwhSlMJvwHnFgVb96CkPkAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\sin{\\left (x + y \\right )}$$"
      ],
      "text/plain": [
       "sin(x + y)"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(expand_trig(sin(x+y)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAVCAYAAADhCHhTAAAABHNCSVQICAgIfAhkiAAAA6JJREFUWIXt2FuIVVUYB/CfFuVkIF2IqJBNmfYQWhRRkWRZTkRR2EMIkoY+BF2IIMJAGuphIgyLbtBDWBB0cbCyIgZKaUawGEOQMqJiCm0Gm0ormqKp08O3DrNnu/c5Z+LkGMwfNnvOd1/ru6y1h2n8r/ESDmD2EfZ7EWpY00goS0Kb/vt4GuJi/I37CvRTsBZb8CVGcQj9YmEz2+R/C4ZwYpVA5ujYqF4cREeBfoeI7zu8jG68kGRr2IwZbfB/SbL3YJVAZuo3ar6opudLeFfjRodXzun4VsR+S5vi2ItvcEyR0ZUclT2rk8xq9OBrUfY/YwdWVjjLjG98hlcwgt8xgBtKdB5NOktbXxMi+zU8VcLrTbzlBfqMFFst+c3joUTvLBpbgicSc7fYuPpzQZIZxa5kvFtkfV/SeaQkwCzxtonBvBMb8aLYrL9wVUFnAGMmP8TvT742lvAWJV+fmVghjyedsuq9JvE2lDnLNG69c0pox+F9/IkzK+zVRIby6Ez0d3O02WKT9lT4r8KxSae0AhI2mdgd9Qp8VfkhMCfxPy4zlvl3M2p50rutwt6gkl4XM2Ak93t+ku+dpP8NSe+dBjJniY4YxF1J/j2R6CqMYriMkWm8UXPxDD7Hbw6fZesq7L1RYa9ftEQdlxnPcqu4J+nsxclNZLtzse7ACU3k94sKR5RtKzhblOFJ6BNZPyQWmmEVjq/QPVhBHzOx7EfTe1aLMd2JJ8XsWYofm8h/n/t7jUh2I3TkYpqATHVFPW1ij+exIvG6JmEPtid+HWek3/0V8nncm2T34LQW5FeIa8dQ0nuuifzMJP9VnlBHvQ3K5sm89O4p4V3ZQqCtYEhkfUETuQfE6bZbnJoHmshfL07aT7FQjI61OK+BzgJxfdhdJ+Q36iex23NLFAfTe0mB3pmctgM1fIhTjSemiPXizrNLtNtIhVwdV4gb+z4sE4lYL0ZO8e6Ux6Xpva1OyM+oX/ERFotPhC9Elb2FZ3E7XhdVtR/n4zq8hlubBNwqesTtulN8z+WxCg+nmPrEIC9i0HirL8LbYpZeKyqW2LgB3CTW2ldiZ1ny82ZVoPOwFT+IHs3Ppcvxgai8X8QsuVlUWTtmFHFcD4uEFdGl+uuh/mzPrWM4xbqwxFb9QrmzhDdHDPGq0/qowTqxiAunyP/dyf/iKfLfMmaJy+jWKfDdIf47sbnIKDvhphpj+ETcywbE59GRwrn4A4+pvv9NYxptwD+TmQ4IdSskCgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\tan{\\left (2 x \\right )}$$"
      ],
      "text/plain": [
       "tan(2⋅x)"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trigsimp(expand_trig(tan(2*x)))"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "iVBORw0KGgoAAAANSUhEUgAAAwQAAACWCAYAAABgvU83AAAgAElEQVR4Aey9f2xTV/73+c6zXSno4bubsv12nRVV6w7db5MtszgapDjz7UjciI5wNiPVgUrYohU1RQKnowEHpDYuf6QOoy0OHdGklWgMzwyyWbU4SEVxt+WJkaYzNhKzMfulG/MI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KWRqvdKPeLcxYuDyCtmehqFKbEp18iQASIABEgAkSACKwGAiQQrIZWoDIQASJABIgAESACRIAIEIEVIrAK5xCsEAnKlggQASJABIgAESACRIAINCEBEgiasNGpykSACBABIkAEiAARIAJEQCFAAoFCgn6JABEgAkSACBABIkAEiEATEiCBoAkbnapMBIgAESACRIAIEAEiQAQUAiQQKCTolwgQASJABIgAESACRIAINCEBEgiasNGpykSACBABIkAEiAARIAJEQCFAAoFCgn6JABEgAkSACBABIkAEiEATEiCBoAkbnapMBIgAESACRIAIEAEiQAQUAiQQKCTolwgQASJABIgAESACRIAINCEBEgiasNGpykSACBABIkAEiAARIAJEQCFAAoFCgn6JABEgAkSACBABIkAEiEATEiCBoAkbnapMBIgAESACRIAIEAEiQAQUAiQQKCTolwgQASJABIgAESACRIAINCEBEgiasNGpykSACBABIkAEiAARIAJEQCFAAoFCgn6JABEgAkSACBABIkAEiEATEiCBoAkbnapMBIgAESACRIAIEAEiQAQUAiQQKCTolwgQASJABIgAESACRIAINCEBEgiasNGpykSACBABIkAEiAARIAJEQCFAAoFCgn6JABEgAkSACBABIkAEiEATEnjs008/bcJqU5WJABEgAkSACBABIkAEiAAR4ARaGGOMUBABIkAEiAARIAJEgAgQASLQnATIZag5251qTQSIABEgAkSACBABIkAERAIkEKzHjvAwCq/gROBurmG1y10fRe+rASQfNSyLNZBwDtETBzB6MY7MT3Uu7qMkpt51onNrD3qFHvQ4RjF1u3HtWefSU3IKgQdRhK5nlbMm+80gejGOZq19kzV2iermkLgYQarE1ZUNziLiaMO/dO1A7y87YHpiEzYt+s+Mrt5e9L7kRbSpv30r23KUe2MIkEDQGK4rl+qjOEb7nci9FYBrS2vDytHaPYzJF6cgHA6t0pd9w6quSbgVwts+WB8G4OzoxYEPosjUY8yeS2B0Zyfcd/owfSuGmWgMwf45uDsEjN3UZE+HK0ogcy2AiWuZsmVIXBzD7I9ylPsRDL3Si17rs2jf2ofRa2t4qJyJIvBRFGVrfzOIsRsLcuVTiBwfQO9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AsvzCLQ689Gg8nQPQYOgaDZKgBLoFQEjbD8svSPGAGGoA/vtPOapMdCrLxStlxKgBHpAQM9aYCP1PoqB/50c5JF8GoZz2FLdQd5Gt/yTcRj2jCB0l0dk0QTLx2S2QUD4vB/J1W0K9+ry2xwSV0fAmiyY/qVSiTwSd3hwJy1VS15J9GyyoDL/IgWesYA7SGYtROTXK8tqe0wNAm15UmmUACVACVAClAAlQAlQArUEPjDDOkoS40im80A+icT3HlgPN7eXSPe+AcYhPZJPs7BfMCD+nR/ec9PA+Z27R0j8lUd+2A0nk4PvdlyOTi/jWQxjet0F56FKBhmEzHtguBhG7McwYGJh3AfIjhEeZWqpanZOlwxphpIKogQoAUqAEqAEKAFKgBJQIyD8awQffsUDl+axNppA31MrNt6p/WFqLS+kC3fH8OFpEbOZebg+InsgxpD6cq7GsUQO8ZNWREQjdAcHsffeHHB0ELr/s8FzhevI/gGiHTUI6t87epUSoAQoAUqAEqAEKAFKQAsCi9MYZL1IMx54jk1DHF3rwSZeLRrSogyymfx9O8IX5rFxToBzqg+hezZ5P0WLEjUrRg0CzVBSQZQAJUAJUAKUACVACVAC6gRK7kdJDjfm1oKwdtupj7pyXbmSvjmIwQkDbEdFDE7MYXKocrlQV1RQrITuIVDEQhMpAUqAEqAEKAFKgBKgBLQlwMJ8oijxFAfLn8wYIC1nj7phRQLJtw7YdogxQPSiBoG233QqjRKgBCgBSoASoAQoAUpAkYAOg4fd8hXbaLVnHcXs72JivxO+6zaMX7DDtIPaR5cM7aCbQVWhBCgBSoASoAQoAUrgnSZAgpH9LQb7bzE4PninW7qrGkcNgl11u6iylAAlQAlQApQAJUAJUAKUgLYE6JIhbXlSaZQAJUAJUAKUACVACVAClMCuIvA/W+PcLBQShgAAAAAASUVORK5CYII="
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.4 Powers-指数\n",
    "我们先了解一下，指数的特征：\n",
    "1. $x^{a} y^{b}=x^{a + b}$\n",
    "2. $x^{a} y^{a}=\\left(x y\\right)^{a}$\n",
    "3. $\\left(x^{a}\\right)^{b}=x^{a b}$\n",
    "![image.png](attachment:image.png)\n",
    "\n",
    "正如上面提到的，为了使SymPy执行涉及仅在某些前提条件下的简化，我们需要对我们的符号进行所属集合的设定。\n",
    "* 默认情况下，SymPy的符号所属集合为$C$-复数集合。也就是说，除非表达式中的符号所属集合为$C$，否则该表达式的简化不会成功。\n",
    "* 可以通过symbols函数，指定不同符号的所属集合。后面，我们指定x和y属于正数集合，a和b属于实数集合，z,t,c属于复数集合。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "x,y=symbols('x,y',positive=True)\n",
    "a,b=symbols('a,b',real=True)\n",
    "z,t,c=symbols('z,t,c')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.4.1 powsimp-指数化简\n",
    "若表达式中存在指数可以化解的情况，可以使用powsimp函数。 指数化简包含合并指数和合并基底两种情况。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAYCAYAAAC4CK7hAAAABHNCSVQICAgIfAhkiAAAAgFJREFUWIXt1k+IjVEYx/HPRcKSFCKLmURTZtiYBTulWNFYzEbKhqIspFhoIrFgM5KahWZBoqYsRcqCUjaYmrGSLIxMIU3k77V4zujtnfua95rp3lH3W7d7e85zz/P8zvm957y0aDhnca9ocF4DG5kpXXhWNNhMIYPoqyO/C0+LBmdDyCk8xwTGcRWLZmHeLMuxCr9wH5/F7nRPJsxUSAXzcQgd6MUOHJ3hvHk2pe9jOI3NeIObWDDLtf4wIGwzHYPKW+s4vmJtJrYRVbSXb62YNejHMN4Le33HmRq5J9P4RCbvWy62raDODVzPxdqEkHW1/nA3De7JxStiBas4n2LL8Ba3hJ06sCE11FNj7qVi9SY/Q2IRsrHFBUJGha2y7MVHBdbqxE+MCO9PcjGJGMjE9qWJKpnY/pTXVtBQlkHlrLUEP3AiE6vgIS5NV6CamiIsURUPVvZw2JUK7BareQRjpor7W52+EnndwoYj2JJqXcMrscuFrMaXlHg4ibiDhbm8Ci7jE94Jm1zAgxLNUV7IQbwQdn8tjt4hrChT5JwQUMUjsb1zmqJ7ZDzz+4BYhf+OXnGDjokdudLcdv6NneJsHxavBaPiQVvfzKbqZauw0EusTLEesSu3m9VUvXSKY3PM1DvgiRBTdOvOGdrFDf1BvL/k2S6EPG5kUy1atGhRk98kcXJgqeDjXQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x^{a + b}$$"
      ],
      "text/plain": [
       " a + b\n",
       "x     "
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powsimp(x**a*x**b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAYCAYAAAC4CK7hAAAABHNCSVQICAgIfAhkiAAAAtlJREFUWIXt102IVmUUB/DfayROI4iFYJIf4GC5SaRMoqaVK1slutCFaEabdFG2UBdlBH1ALZI+yCC0TZmKohsZWmQkfdim1FoVfWBTCRl9DWk1Lc6Z3jvv3HvnvjoVxPw3l+c8/+ecc895zjn38j/HK/gOvf+SvZswjE01nIfwEX7GObyMaXVKb8afeGBifGyMQxjE9JK9Fh7BbZiPFTiLbXUKB/ADeibUzfFxi8jKjob83dhTtblIZGP3Zbt1afgEX+CKDvlc7MIpfC+u10U8OkKY0nHgbpHGfSVGBkTEVnXIWyIyw3giZVtzvbXC4evxG97qkL+GeeLqjOAanMRsPIh+LMvzH1bo9wF+V17kS/AHPjY6Yk+n08UsLk/Z/go7A2nnxg75ijz3VEG2Xlz1VkG2IXkLy5T3pvJTFcZpR35Drnfkep/R2b0Sv+LLEh1r8swzJXszcu/9guzO9Osu9GGLaAqdL/c3FqWSgZoXuQ5D+Bybk38MU0u4x3N/TkHWi6/wbTpdhiF8U1i38Bx+FCNhl8jYm1VO3qod3To8nrxhnMBVFbzHjK2pJ43OaBnOigx0heJ1GMpn7ZARw2gEm8QVKsOJfC7P5w24H+9gb43+noIvl4Q5Ilpv13DWivY8mNwXargzk3s812+IZrG05syUPPNpM5fL0RJ38FzF/kpcEM1gluj5F0Wkq3AGv2CdePHnx/FhcfIONva6AgdSUV+H/HZxhT7DtSlbndzDNfpeTM5PIkBXj2N/Y/I3d+V1CdamovsKsiWi1Q0a27dPJr+/Qt967cZwTwP7r4pCn9vc5XJMFa3vvVz35fq8scOL9gB7t0Jfv/ZcKO35BcwQRV6X4a6wPY3XFWVTHBEFvqwBd4v67HaNaeLD7ehl6hkp8GcbcHvwtajRCcUdeFj3P1bzxD/CS+Kj7rTqgVnEYuzEgi7t/WO4V2ThPF43+vNkEpOYxH+IvwDjZ6+3m6QgRAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(x y\\right)^{a}$$"
      ],
      "text/plain": [
       "     a\n",
       "(x⋅y) "
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powsimp(x**a*y**a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于合并基底(第二种情况)，要满足一定的条件才能够进行。首先，x，y需为正，且a需为实数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC8AAAAUCAYAAAAdmmTCAAAABHNCSVQICAgIfAhkiAAAAh9JREFUSInt1l9oTnEYB/CPtaFMDS2W9Ca3ttekuFG4kFsXblwQN8qFK0XkRknNFTcydjOJ/C8Jk1I0zEyusJUmXJj504SYfxe/39r7ns7mPbb3avvW6dd5vs/zPc85v+d5focJjA34jlyB7TB6UFtg244/2FoG7f/GFHTieLzfibdYlPA7ISSfL4P2mLAWg9iNASxL8XmMb6gsg/aY0Y6fWJfCTcMPPBhv7YoU5404hW58xkc8xJYRxNcI5VCBvhS+HlV4hCW4gPf4gjYsHiXxf2kXYaawTffQgoNx7RdqdlfCP49P2IzLuJaiuS3GXo0Jn0cT7kR7H2pS4krRLkI15qXY64RdeFZgy+EN9sb7BvzGykRsc0yyH40JrjVyexL2UrVLxnPDWzcbT3Es4XMWdxO2TiOPyeWRO11gy6JdhFnYh/tCrf+K4kNX12jBKagSZnWv9EmTi7qXMuqSEGwQGmguOnAGH4QeWIhNeJJRvx5TcUWYGEkMHUAvM+qiOPmTQuOsxu2E3/64dmbUXxrX3hH49XFty6hbhAXC9l1P4WrwKvIrMuoejXEHUrg6fBVGctbDqwi18SHdQp0OYQ5uRG4Q0zPqdsTYF5hRYK/GTaGn0g62zLhluCmbhDLqx7n4kKz1Xin8EnQJI7YHh3AEr4XRt2M8Eid8/Va8E2Z6u9CkjcJLtWTUy8e4ZszHReH/ZEDYzVXjkfQkJjGR8BcL5pbwzjNEowAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$a^{x} b^{x}$$"
      ],
      "text/plain": [
       " x  x\n",
       "a ⋅b "
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powsimp(a**x*b**x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果想在不修改符号所属集合的情况下，继续进行指数化简，可以设置force=True。这样，可以强制简化。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADQAAAAWCAYAAACPHL/WAAAABHNCSVQICAgIfAhkiAAAAwBJREFUWIXt1kuIlmUUB/Cfk7fBCW8MJWFDdIEgnazosggqJNq2aFGLQlsE3RYSpEWbIIKpTW2iKTdGaKUpSHQjCAorm4xoUSqUYnbR6YJRQ41li3OGPp+ed+b9HAki//DxfO/5n/M857zPubz8T7ABhzDvJOx1J45h9RR6l6be7Q38TfgNAx2yJ7AX/ZNtfBn+xJoWzrbBs8LRwRa6W/EN+ircDIzgmXy+D9/h3Kk2fQM/obeFA23wMcYws4Xu5SL4Bxr46zGOtTgiXv6kuEDcznAbT1tgDn7HB13YfIb9OK2B34GjuKFG9hTPq8XVvtCw2S14HnvwM37Eh1jVoL8Ms/ARLsYWfI9fRCZcVLHZhLOxssJdJ1K3R9T4lBgR0deaweniut/Dejya66hIk/srNnck90oGsRlDeCflh7CgsFmZ3OOFfFCUwm3YhlenCmZeBvNpA9+HMyvyJeK2Pq9ww+ncKFYU3Ab1epmf8p0dsgEcxIP5vFyUxtUNviLq55hIhW6xWz0FRjS37CuS21jhxvBt/l8k6urpQudFvDuZU1flAU31sxAP4X1RO3+k/sRvV6E/S8yNfeodbiDttla4gyJbukbnQWO5zq3oLRc3d4ZIhU34QdTUObgVnxQ2yzAb2xucmxiQ+ytcb4c/XaEzoImUWVzRe04U77V4u+AeznWkkF+S676Gs2/MtUzxnjzrywa71pghgjpcyJeK1HitYrMAB5K/suCeSvkjFbsl+FW0/zIdL0y7LV343ojNudl5HbL+lO0RdTGBxXg9uXH/TNWdyX3h+DHQhzdFDdaG46q0u/tEg+jEzbnZXYX8LX8X/pBIwVG8lI6V9TNT1MAu0c734jE8ia9Ey723wYeNouaWTi+UwGzRLstPlX4xNw6LmbNDNIIVItD1hf5gyodxFl4W315HxK1e03D+fPEitk0vjOOxLp0pB+G/gXvy7EkHZreYK1rp9pO5aQv04mtRxyeM2hftUZH7c0QrHp/OAV3gfDGIh8Q32ymcwn8BfwEz7b8t079ydAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(a b\\right)^{x}$$"
      ],
      "text/plain": [
       "     x\n",
       "(a⋅b) "
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powsimp(a**x*b**x,force=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.4.2 expand_power_exp / expand_power_base-指数、基底展开\n",
    "与指数化简相对的，是指数展开，同样地，指数展开包含两个部分，指数展开与基底展开。其中，指数展开对应的函数为expand_power_exp，基底展开对应的函数为expand_power_base。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC4AAAAYCAYAAACFms+HAAAABHNCSVQICAgIfAhkiAAAAdNJREFUWIXt1k2ITnEUx/HPMyRZ0hQiCxaz8lYyxWQzWbAiGxuNbCzYSVgoC7FgQ1Kz0CxsFGVHpCwoNeW1sJq8pJEphrzk9bE4/2e6bs81Pd1Ld/H8Fvfl/P99/+ec//mfe+mqch3F9aLBnv/oSKdaiQdFg3V3/H7RYBWOH8ZDfMQEzmF2SWYvFuIXbuCzyH5/Se6UGjiCdViCQbzCgZLcjWjiLjagD1fwHDNLsgs1jJGSjP34KpLR0nIRzDLKl8pinMIjvBXlshMvS3JX4aLIcEuf0r1n6pLRNRHV1py9IbLYxPFkm4dRzMc+DGCNyFS+G3TCJQ7mvdzc1XiPMW20Aj/xGDMy9pMJPpyx7cBkWryloTRvaQnuHPzAwYytgVs43c7plkYSbCi9H0rvF/y5Q5vTAltE3e3FeJtgOuX243sKcm1in8czzP2b44vwJU3ck+BXMSs3r4Ez+IA3otZP4GZJ7m48FWX1QrTCS6Ikp9WxBG7itti+KlQZt6irTGSed4moq9C/4oLt4os1LjJztuZcsAnfRF/uxRNxUPpqygXrxdaNYUGybRPZuVxDLqLPToptzPfg0bTIQI24iD75Gu/E/0Beg2mBOzXhdtVVV3XWb7Xkj1vRu6cYAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{a} x^{b}$$"
      ],
      "text/plain": [
       " a  b\n",
       "x ⋅x "
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_power_exp(x**(a+b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC0AAAAYCAYAAABurXSEAAAABHNCSVQICAgIfAhkiAAAAe5JREFUWIXt1j1I1VEYx/GPRRE1REVDUi0JGULSEC25BUFOhQ02iEEEQUHkEg2NlVBD0gsZhGu1RFNIQwZF1Ja9bBE12Atk9Eqvt+E8N+/Vq3b9/9VAf9t5OOf7e/7POc/5H2aojuIhPuEtLmHBZHLnZATXYC72oQGt2IqD/yl3VHWjZzK5WSu9Cl3oxztpK3fj5VRye1HAjmHxGukrCzgRsWV4hSvS1jVgXRi0lKztiHUdoyS4Ft9wu0ruXzXiF55IZ6qoU2HcXRJrw/v4oKLaY96aktimiF0dJele/MT6Krll6okJ7TE+EuPLyo9Tc5htRx0OYKCC4Tx8wYsKXjuDfXoC3DKtxFc8x/6A3sD8YfNqcBYf8EY6gydxqwKzLzi1JbFF0hl9jcUT5JbpeJgUcAcLx1swjo4Z2Sudync0sw4ZSro+B15zsDpjXI/vuGuMLa9GrfgtnaMCzufAXBLMvhjflBp+Qw5s26QK9GM5nuKHfKr9GJ+xSyrGuRyYNktd/gwrItYSBtdy4F8I1kfpLbE0K7BRulIGjLwLH4RZU0aPNkN9sicjS530Bxo0dMGXaksY3cvo0xSc+3JqvqnQdan5Nk53Iv+qYvOdme5ExtNqHMZF6UH0SPaf1KRrr1TdQenFVjv29FnNaubqD9Lcj2aiqS1fAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{a} y^{a}$$"
      ],
      "text/plain": [
       " a  a\n",
       "x ⋅y "
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_power_base((x*y)**a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "同样，对于展开基底(第二种情况)，要满足一定的条件才能够进行。首先，x，y需为正，且a需为实数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACwAAAAWCAYAAAC7ZX7KAAAABHNCSVQICAgIfAhkiAAAAmpJREFUSInt1kuoTVEYB/Cfez2urroDMpBHiYtIRPLMwGtoYCZ5RikmjJgwkddUyMArKSHPEpLIFUIKSTFQ3gp55O0YrHU4bWufu917TeRfp7339//W//vvddb61uYfwW48R/1f0B6BEhZUyemJnXiKj7iFKXnJI/EdyxLcslhsZsu8/sQhPEGXBNcLD3EU49GI+RidJ3YKr9E5we0RDA9onV+jos7KBHcCTagpItQozO62HP4O3hYVawZ38AC1FbE+wouMKiqyLg6YlImvj/HUb1bMaaqSU8K5jOaqGJ9WEZuOr6pMSPvM82R8w6VM/Bp2YQ4u4nQFVzZyKBMvYx5642wm3hSvU3Ay3n+JZrvgTZ7pMuqFt7uZwy8SZmRhc0IV2BjH7PD7rDVE7kpFrCteYi8GY2CsNyQl3hgFTuUU3xr5kQWMtsPmmL8pPqfwQWhdlRgnzP47vIp+uqcGj4kF9uWIX8FndGrGbK2wfErC2q+GR8K/2iIMi0WOJLj2wmzcaEajA/ZHnVUFar4Uuk6L0CMWupDghkZue5XxdTge85YXqFcjtND7f2bzF9oJx/GLBDc7GlmaM7YeZ6KBxQXrDYqaB//EZOXOLeE8uqFfJq9rvKZaTYOwMSZiLrYUrF0+arPtriqyffggZgjN/F5F/Fq8rhFazHvcFtbrXowVNmVfrE7UWYtPmdhUoeen9kxhdBTazOUEtwR3ha+nUjRfI2yaaifcs4RWg7CJD7fGbBkrYqHhbSGWg6WxxoS2EKsTPkqOtYVYAp3xGAdaMrg2EfuK68IBcVU439sS/YX1vEH4jP2P/2gNfgAHOZ+V7LNGfQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left(t z\\right)^{c}$$"
      ],
      "text/plain": [
       "     c\n",
       "(t⋅z) "
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_power_base((z*t)**c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACcAAAAUCAYAAAAOTSQ2AAAABHNCSVQICAgIfAhkiAAAAYlJREFUSInt1r9LV2EUx/FXphgkBAlOmmOC5SQ5CG0uLS5NIVqDQmBL/QFOISE0STipidTg4GIKSYSDEoLQkIh/QKCLgRbZD/w2PI/w9cv1er3XGsIPXO69nOe8+RzuOc9z+c/UiElsYR+f0PU3WFUJCY9Rwr2EWBM+4Cruog3PsZfDWC7WdDR3PSG2gGXJRZ1WuVgbgvvKpGbB9K0zMHZq1rOYkHT1oBu/nVzpcgqnhKWsrOqy5zW8RB9WsFgWW8LNCKvDbgpztiL3UA9wDe/xKyPriAaE6voTYvXYwSu0oiWuu5GBOxK5E9FULtZYhLQfE+8UPttXfMFbNKTwLuBFZI7G97wsq/iJ2rRFGXVRaJOS0M+FVI3v+FgUhBrMCMaGzoCnLcLGC3IuYS6ynhQ1dajeCHxUgHEZ73CAh0UNlW8l9fGeebQrdAXz6MB9TOW3FVQ+PbeF/ewzXuMb1oXeyaI3uCMM1cIxa4bxI5dTDGJT+EMo4WnGvCrhyEs7GbbzmjrXuf6V/gAbCXEq0wIkAgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$t^{c} z^{c}$$"
      ],
      "text/plain": [
       " c  c\n",
       "t ⋅z "
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_power_base((z*t)**c,force=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.4.5 powdenest-指数的指数化简\n",
    "对于表达式$\\left(x^{a}\\right)^{b}$,含有两层指数，可以通过使用powdenest函数，将其简化为一层的结构。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACEAAAAYCAYAAAB0kZQKAAAABHNCSVQICAgIfAhkiAAAAbBJREFUSInt1E2IzlEUx/HPgyRLmkJkYRazMkPJFJPNZMGKbGw0srFgJ2GhLMSCDUnNQrOwUZQdkbKg1JTXwmrykh6Z8paXvD4W5/z1968HZZ5/U+a3uvfc0z3fc849l/9EB3H5dw7TaoDow53JAHG70xD7cRfvMI5TmJVnXViA77iCD6Iq/RMQ96caOIBVWIxBPMOePF+LFm5iDXpwAY8xYyJBqhrGSK5341MCFlqaYN2F4V/bsQjHcA8vRUu24mmeL8NZkXmh99XYVYhLSbmxYm+I7Fo4nLa5GMU87MIAVojMi2now63KXcvxBmPtMuvFN9zH9JL9aAIMl2xb8DoBCw2l3xLMxlfsrSRzDcfbARQayYuGcr8v92f8Wrn1GWSD6O9ONEtg/fiSCa1Mn9N4hDl/gliIj+m8IwEuYmbFr4ETeIsX4m0cwdU8346HorVPxHieE+37Kx3K4C1cF6XtmNpNx3hpvU1kUas2ix+uKSpxsm6Adfgs5r4LD8Tj6qkLYLUo+xjmp22TqMb5OgB6xWg1xYyXNZogA50E6MZzvBL/elWDCXGjkxBTmtKk0w9lD2Sc+PxRxQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x^{a b}$$"
      ],
      "text/plain": [
       " a⋅b\n",
       "x   "
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powdenest((x**a)**b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAC8AAAAaCAYAAAAnkAWyAAAABHNCSVQICAgIfAhkiAAAAqdJREFUWIXt1kuIllUYB/DfN6M1NsFAEoigguaQmxi1vCTiRm3hylq0k8yNQRKUiLqwREQsV5IuZuH9UuhgURApUUGBXTAvoC1SLPA6IN4wRFMXz4k+3znv5zjvKATzhw++95zn/P//97zP85zDAB4ZVuNA2WTTYzTSF3TgSNnk/8H84bLJMvPbcBGtFYRX4Ciuoxub0FI3PxF3saBk/bMYjjv4BjfEV5jSSPTFtODdCsZrWIlpGIWZOIOlhbh9OIenMxyzxcsdwgw8j6/wJwaVCe/HZQypYD6HTmwpjE1KBpdn4pfgpnj5f/FCin8uJ9Audr2zotERWI9juCRS5xZWZWJPiN1sLozvxs7C2Bhhvp2eOf+m+OSfZkR+TAvLft+nuKH4BcOwGNPxktjFXOf4BCNFatWjA78VxibgCk7RM3dm4h8czIjsk++585P4t+l5jijM19NLwRui+ItmiE2BWfg6/X8KYzG4Lq6Gd7Adt4skrWnwWEagDB8lg5v99xXnJJ65IjcXiaK8nAwU0ZY4fq4bmyLS7DgmJ54dOI1nckbaE8n+XpiuYWOK/7hgqoYNuCra7Xqsw3cN+P7G+brnhfgdr+Iv0Sa7RCpmMTWZyeV7PZqxNcWufUBsb3FGJhUeBh3C0OcNYgZjT4p7v4pYAZdwrQrBcGHqh5L5FnyZYt6rIlRAk2jPJ6uQ1ESOdmfmWsURfQdvVRHJYJzYkK6qRHv1PMHaRDu7jXlVBTKYnzTfftiFxT7fhdfwCv5IY7vwsmhlo/FBhmeNOIT6gtnibGlUa73CE6Jl/ZSem0QhNTpZL1TQaxNt8rMKHPdhmTA1vr8IG2BR0preX4Qt4qL0RX8RlmAIzoo66xOKNzmiMA/hSfwqjulHgbGiTj4UV4cBDGAAD8A9z0yh35xZjzIAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left(z^{a}\\right)^{b}$$"
      ],
      "text/plain": [
       "    b\n",
       "⎛ a⎞ \n",
       "⎝z ⎠ "
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powdenest((z**a)**b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAB8AAAAYCAYAAAACqyaBAAAABHNCSVQICAgIfAhkiAAAAZJJREFUSInt1D9IllEUx/HP+6ogOQRGIEK1FDSFBpIQ4RIOOtXSFrrVEA1FNBUNIlKTVIODFbZZuBgNEeXgolBaEE3RHyIyEEsLRLGGe1+46GNKvj6B+IOHh8s993zPPfecwxZWF56stlncZHgDJv8nfGIz4FfwCnP4hn5UJ/u7UY8lPMUvIQvNG2CCAq7hKPbhOD7jcmLTit94gRYcxGN8QOVGA1iuPtxN1pcwH4Mr6VAMaD//nvY96MVrTAup78SnxKYRD4SblvQz/otZ8NEY2WrfCHZhHHW4iGNoirdMK7sBL5f5P4zveMfK3A/J7stO7MUztAuFdSoGBB2oSWA7cABViY8CzmMAixmMTF2PkDtCptrj4RPC253DF8xEAKGiF/AGR6LdfbxH7XqgBdyO4JuJ4wJu4QemhLe/gefJ2TN4i5P4KLTZQ+Gp1lQF7kVwz3oOlEtVGIzgq3mCqzEcwRfyBNcIY3AJZ/ME7xR6fBGn84KWKvgR2jAmzN8sdQuDpKwqYtbfJ9vXckO3ta3c9Qf8dmCXlhMvKwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$z^{a b}$$"
      ],
      "text/plain": [
       " a⋅b\n",
       "z   "
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "powdenest((z**a)**b,force=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.5 对数\n",
    "SymPy和python以及大部分程序语言一样，log指的是自然对数，也成为ln。SymPy将其等同看待。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADsAAAAXCAYAAAC1Szf+AAAABHNCSVQICAgIfAhkiAAAAzxJREFUWIXt10toXFUYB/CfGY1NK0yhiBFULhpT3VhEER+tCnblUqTYjagVN1aKBRetC11p1bpQfOBjkbqphYKF4oOsfIJWRaFWbRdpqsaxEdEqGovWuDjfkMvcc2cqmZKF+cNwZv7//3l893znO3f4n6LALMYWcA2vYBrL5jHGFVIcG7qZCgsb7JX4B5v7MNZraOGsOkNhYYMdxy8Y6sNYV0mxbK0zFBYu2FFpV1/s45hf4QgabWLgJDuuw7s4hhnsxxacmfGehk34En9iCs+gicn4dOKu6LerZv5xaSNuycw1Ftq2Du1VXIC1uQEL+Z19JPgf8TyewBfBvY0zOvzPhTaFp7Edh7AvuMnM3J/gb/WFaRVOSA+wUeKfjLlyGbE2tO25AQvVYK8J7hsMl/jTsVf1XKwJ7iCWl/hBKTNmVYNdJgW6P7eoEsai/x3xe2v83iWfoc3Q9+UGK1SDfSm4ezL+UelpT5S4l8N/e8Z/nXywo8GP5xZVwnnSEZrExujzlvQg6zCDH3JCoRrsp8GN1Ax2JPTlHf4LM94G/lINtp09dee1jEfDO4sPsLSHf0rKGvQuUM1oWzV6q8PXbo9mvCfwU4afiXZJj7WQ6kYbG/BHD/9QafyewR6LdrhGP7fD92u052S8DazI8NPR5rQy1kvFpp2Wm3r4B6SMmy4T3fBZtDdmtBHpHB2WXgbK/tUZ/9VSYetES9qxlV3WcTN24AAuw9e4G5d06bNSupo+z4mF6pm9NrjDOLvEN7AntAdL/A3mqnGzxA/iHfkCBbvV14bVUrpOmMukW8O/JxdI4M7wbMyJhfw9+1jwR/EsHpeuiVm8p1oNXwjtOzwlpd5Bc/fshCrWR597O/hVUta0cFGH9nH0WZMLBjul4nR+TizUvy7ehvfxm/RWdEDa0VxRGcD9Uqodx/fSQ2pG/1xaDUpn8aMSNxLcz1LqdqL90vBhRmtKhanbzp9SXCwtbmeNviX0y/sw132673rfMKxa+Jbi9VjAupp+S6R7e+885x+Ssmn3PMc5KWyTFr0jvo/hWynQN6QKWYfr8ZD5/Xm/FA9Lx/KU4ya8KRWV4/hdupIeUP3TsIhFLOK/4V+cot7JLDACIQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\log{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "log(x)"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ln(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对数和指数有类似的特征，如下：\n",
    "1. $\\log{\\left (x y \\right )}=\\log{\\left (x \\right )} + \\log{\\left (y \\right )}$\n",
    "2. $\\log{\\left (x^{n} \\right )}=n \\log{\\left (x \\right )}$\n",
    "\n",
    "$x,y\\in{N*}$\n",
    "\n",
    "$n\\in R$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "x, y = symbols('x y', positive=True)\n",
    "n = symbols('n', real=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.5.1 expand_log-对数展开"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI0AAAAXCAYAAAA2o8yAAAAABHNCSVQICAgIfAhkiAAABNdJREFUaIHtml1sVEUUx3+2UCk1WTQxQaLkRmurL6IRxQ9QEnjyxcQoER7IVQgvYowSE8EHfVLUmqhBCerD4guiRInEjzQ+iErQ+pkgiiaWRa1rNaYaorVRXB/OudnpvTNzb3fv7Qrdf7LZvWfOnJnz75wzZ+YW2mijCQRADSi3cA4vAD8DPU3YuBzxY10uM5o6AmYQjwGtdXYx8C9wTw62XgWqwBk52JoqAmYQjwGtdXYQ+A3ozsHWlYgvW3KwNVUEzCAeA1rnbB8SHc/maPMr4BjQ2UDfEOFieQN9A05xHjsydlwFvAv8DowDh4DNwOkW3dOAu4Avgb+AEWAbUAIq+onjdu232zH+IPKHuMkyVlnbtsbaXgQWAisdNluFIrn08bgJ4WmTY179wITOzYSXxwB7hDyk8l+A7cBjwBcqeweYHdN/RttGgKeAAeAbYEhlFcvYHwP/4C7cFgEnEPLMzPG4jmWLrJXaNuCw6UNIMZmmaC59PC5RWy875j2ofS+Jyb08BiSdvVpl3wH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77rSLkVhmnlcAbyJFK8TwB/Ike5eki/k2vAjDy43IItsDHiJya8Q2mijjTbaaONUwX+XNvY7FqUs/gAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\log{\\left (x \\right )} + \\log{\\left (y \\right )}$$"
      ],
      "text/plain": [
       "log(x) + log(y)"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_log(log(x*y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI0AAAAXCAYAAAA2o8yAAAAABHNCSVQICAgIfAhkiAAABMhJREFUaIHtml1sVEUUx3+2UCk1WTQxQaJkorXVF4kRxA9QE3jy0SgRHogK4UWMUWIi+KBPilofNChBfSjGBFGiROJHGh9EJWL9TBBFE8qilrUaUg3R2iiuD+fc7HTvzNy77L27Qu8/abZ75syZc/6dc+6ZuYUCBZqAAarAYBt9eAn4BehpwsZVSBxrMvGocRimEY+G9ga7EPgXuD8DW28AFeCcDGw1CsM04tHQ3mCHgN+A7gxsXY3EsikDW43CMI14NLQv2D4kO57P0Oa3wFGgM0ObaWA4w3nsSDlxBfAB8DswARwANgJnO3TPAu4FvgH+AkaBLUAJKOtPPe7SeTs96w8hf4hbHGsN6tjmurFXgPnAco/NdiFPLkM8bkB42uDxqx+YVN9sBHk0uDPkUZX/CmwFngS+Vtn7wMw6/ed0bBR4BhgAvgeGVVZ2rP0Z8A/+xm0BcBIhz64cT+larsxarmMDHpt5weCvNHlzGeJxsdp6zeP3kM69ok4e5NEQD/Zalf0AzLXkM4A9xJ93S1X2HTDHknchO7hKPNAedfaAJ5gIgzr/Dv2+Sb/vxF0xSzo+nGA3axjcmyZvLpN4nAn8qevX4za197RjLMijIR7sCypb59DvQ7J/xJK9qPqrHfrX4940fSofcjll4UKknJeB9TrnXYREHyaAnxPsZg2De9PkzWUaHveqzjxL1gP8CIwhG8QFL4+GeLCfq6zXY+yojs+p07/YodsJ/E1800QZ6OtnbDymulVgHzA7QX8Uyb4QypbNND8vJ9gzuDdN3lym4TF6PNq94eNMreAuTOFxRkARajuv4hmvIE1SCTnmRfpjDt2TwHGHfEI/ZyX4AtILRFiDlNsQui37PhxGmsy0ONaAro28uUzD4z79XAy8DlwG3Ad8DGwPzPPyaPBXmks8xuqz4wsarzTzdM5HAacBViLHyYrqb03Q71D9wwl6WcMQrjR5cZmGx3MRTvbq9/eQDXhlYE6Mx6Qj95f6eZNjrBfpM44gmWHrL3HoX4O7slWQCtIf8ONmJBMOIt39IWAtkik+9CPHz68COq1E3lym4XEcuXdZCKwClgHbrLVcCPJoiGfIdSo7ApxvyTuB3Tr2kCW/kVrHbzdVXdSasLJj7V34n/dLkMfQCHCBym5V/d2uQBR3qs76gE4eMLgrTSu4DPEYYZvqnEA22XnBaBJ4NLiDjRqlMeBZ4AnkWFcFPiR+eomc+gk5wg0ggUd3CyPEsVLn3F0nX4BkXoV4Wf9U5yx1BQPsQJq3izzjecHgv6fJm0sfjzZWU2vq16aIJ8ijwR/s7ciz8gTSNB5EssLVdHUgzdUh5IbxGEJQSee7ylwXcqT7xJL1qmyc+IUT1C6d9jvGSkjjFqpEecEQfo2QJ5cuHusR3f8MI4+dENrJIwCXIs7u8Ixv1PFQU5YW9xCuQqc7Qlwm8fgm0vwuSrFOy3icS7zBng28pQ6s8MybhZwg9jS5fjeSkbuatPN/wKlwGeJxlc7bkmLtlvK4GXF6u/4+iNw4VoG3CZfEG4CHae6fhy4HHkEeE6c7TpVLm8f5wIPIjfQk8q4r6VIUWszjMuAdpHmdBP5AjnQPEH8hVyCMLLhch2yyceBVpr5CKFCgQIECBc4U/Ae3A+iS2eaNYQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\log{\\left (x \\right )} - \\log{\\left (y \\right )}$$"
      ],
      "text/plain": [
       "log(x) - log(y)"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_log(log(x/y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEcAAAAXCAYAAABZPlLoAAAABHNCSVQICAgIfAhkiAAAA9lJREFUWIXt2GuIVVUUB/CfTk0+gpEeZFBxKJP8kkQR9LCnEAR9qYj8UpYRgZYVSGhEfkqriSiydzEFYYKhID2YD2FWUGYUaFkRppZNKj2lJlObPqx9meO5+1zHmYYpmD9czrn/9V9r773u2uvscxnFsKBAH7pGdhpexi5MHKT/2WIdc1qJjsUtWIWv0Ytf8V5yHFvRF0Y+Oefgb9w9xDir0IOj6wS3icV+j1ewBC/il8SvxJiSvjDyyekW8xs/xDjnirUsqhNchqs0V8hkbE/O15T4wsgmZ6qommf/pXibsQ1tDaKciLexJg1Yxg94Ot1fchiDXYd1Ymv2YiMW4qiMdgzm43P8iR14Ah3Ymj5V3Jz8VtSM3y1+vKszY3Ul29IS/ypOwcwWa8piQQr2aIkr1FfOA8m2G0/hYWxK3FocWdE/mWw78Dg68RXWJ25rZowN2K++EU/HAZHwthL/SBqrWnEzE99ZEy+LI8Sv3ocrSnwhn5zzEr9dbMlynDWa9/aMxH2JSSW+XVRen+bkTBSJ2XiIuXcl/9np+6L0fYXm9tGRbOsPEfMgdCan1yt8IZ+c5xJ/aybWVPFrbilxzyf9DRn9BfLJmZr47kPM/SSxpbdiXvJ5SyQ+h17RRgaEO1LAzTimYivkk/Nx4qfUxNyW7JMq+lMz2jbs05ycRnXW9ZsyliRtH97HhBbaHaIi0VxaZczFY2LPXoqfBjARojyJc0MOPRVd47ozoz2AHzN8b7qOG8B8dpfu5+CPFtrxpdi1yblTPC02icQMuNTE04mD+00ZJ1Z0v6XrCRltmzicVrErXXO2MmaJttCY//wW2rGimne10LhHlOAnOK6FrpDfVo0ekjuOT9Hcc15w+D1njFjE7qpDCVfiL9G0jxetYR/OqNFPS2O9VhfwviTYoLnHVFHIJ+f8xH+TJtVAG1Yn270l/mL9T6uOEt+Od+STQ5zY63rbhWL7bNFfqdcm/eqa9dyU7PNyxhuTcb84zyzOfGaX9IX6c86DybYTy/CQ/uPAu5qfFs8k23eiz3WKZDXOOVs0Y1bymVvhp4tXih6cVrF9lHxmZOItF2s/OWOzWH9Xr/usLekLrV8frhcvrXvEqfczUTG5JjoWd+EL7BXvd8tEJe3BpxmfdtFLPixxUxL3M87M+DQOeh9U+A7RiOuq6j+J08ViltfYFyb7WUMc53b1FTXimKz5yTlBHDz7xHtaDuPEuWnNEMYeLyp15RBiDCuWikW+lO678K1IzBsO/qukiotwv8H/2TVNtJRikP7Djsvxpmiie/G7OEos0PySOopRjOL/i38ALN8bDXRpJekAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$2 \\log{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "2⋅log(x)"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_log(log(x**2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEcAAAAXCAYAAABZPlLoAAAABHNCSVQICAgIfAhkiAAAA9RJREFUWIXt2FuIlVUUB/BfTo13ZiAig4qD6VgQ2Vh01QrSl3qLkOwhKqOXDCkoUB/qIdLKHoouWD2MEZqgJEkXfOpOF8ViKp0e1KlsUomy22hl08Neh/nmO/ubKUeZCeYPh332+v/Xvqxv7XX2dxjDCUENfegY2WV4EQcw+Rj9L5L2sfi4rcjoCM7F+Bv3DnOcV9CDKcNeUaBm5IOzFT9h4jDHuUTay/JhryhQM7LBaZOy5rnjNN5OdKOpbhhXEiyQNrwS52Md9uNXfIBL/8NkC/EODqEXnViG8RntSViKL3EY+/AUWrA3PmXcHn4bMtzW2McNmXk6gltV4l7G2ZhftaH7w3FTbOhVPIrXwr4fU0NbU505Dwd3EM/iMXwetrdwSkn/THD78CRW4yt8HLa9mTm24S/5QjwbR6VgNxXsj8c8uWybH9zqDIcUvT6p+s8pcZuCmxf9mnxwLg/715hWsJ+MLRrP9rywdaG1YG+WMq9PY3AmS4HprNqI/gy5NfrLo79B44khZWmf9ECy6ArB9RnuoeAWRL8mH5znw35nZow26YnuLtheCP0tGf2V8sFpC/vW3CYCZ0rZvxdLQv+mFPQq9OL7HDElFt4tnc0y1sUE06Nfkw/O9rDPqFhAd/CtJf30jLYJf2oMTj07c/WmiJWh68P7mDSEfp+UkRiYXhdGv17MypgjFdc9Q0zQEm1PBd9T0tXb/RntUfyQsfdGO2GItRwsfF+M34fQTyyMPSA49RqzPeM0FTOxQz5wRRyKdloFf0ZJ93O0p2e0TTg1Yz8QbY6rY5FUXOvHZOkgWlIsWgtjDwhOe7TbMo7toc0Frowd0V6T4WZItWCPdHkr6udm9JdJhbyMHikrZlWs4TqsxRe4ALtwB84dZN2zpHLyaY78DEfkC9Y9UsbcXLDV5GvOFWHfg9MK9iZsDm5FwX61/l+rloK9GW/LF2TYKF/b5krHZ7f+LL0xtJsz49RxW2iWlInx+EN1ZrwUjsUnVVN9z3lE/73oaemu1Bm2dzU+gDXBfYsnpOPQpf+es1sjFoXPXQXbbCkje3BOSf+JgVeRMtZLxfisMlF/M11T4bgTvxh4DGsGf324Ce+F32EpxVfIF9FxUnbukrL3OymoLeGfS/VmqZ58FP0Z0f9ROkpl1C95H2a4FqkQD5ZZow4zpQ2tr+CXBd9ewf9b3G3wrBpRTNN4a52k/7VlYYXfBOnetGUYc0+UMnXjMMY4oVglbXJtfO/AN1JgXpe/lNZxFR5w7H92nYcHpTIxKnEt3pAK6RH8Jv3E36fxJXUMYxjD/xf/AFh7C0mE2YY5AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$n \\log{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "n⋅log(x)"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_log(log(x**n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEEAAAAXCAYAAABUICKvAAAABHNCSVQICAgIfAhkiAAAA6RJREFUWIXt2G+o3mMYB/DPzjnmHEc9K8mU9LTmDFFkiTGUjSjekCRZIysiWf40XuCFPyPvRkLZJCZbmxYyLzTZYnVMMbOSbbRzOCgz6xib48V1//I7v+f+PUedno4X51tP9/N8r+99Xfd9/67fdV/nMI1xaGIMq6dwDa9iBP0d8H2e2N9t7URNU3sI8/E3ltfYl4v13TSJGBswjOPrBE1Tewib8Sv6auyvifXNm0SM85OPh+oETVN3CAMiC15so9mFg+iaZKxd2IfugvivDm/ARziAUXyBFTg2o52Be/AV/sB+rEIDe9OnilvTvDcztpXi4Zwu0vho+j2Gm5Nma4nLfbaU/K3FqVhUED11uy7hCbHhn/E6fsdVib8Si/FXSf8c7sCQeLJ/4lqRisdUtAUWpc19krENYg2WYBs+KNmKzW2o8AWWig1/WOK2pnEx3q9OaGp9HS5M3HeYXeJ7sEnr+7Uwcbsxq8TPFJk0pjUT+nFEZFcdlqW5t7fRVPFMmvOK8RnfSPz23KSm1kN4KXHLMvoB8fS+LXEvJ/0tGf1F8ocwkPjNuUUlvJA089toCszA80m/Kv2uYhQ/5CY3tR7CYOLm1gTcl+yzKvo5GW23eBX2Vvgi23L1oMB28VrlalA1xprkb2Ub3X6RfZi4MDbSOFxjH67oivHHjPYofsnwo2nsrYnRg7NFoT1cu9KoN2tFFj6KB9to+0pxJzyEA2mcXWM/uaL7LY0nZbTdOCHDj6QxZ4MzxQF9Vr9MvaI4Xo/78FgbbZfI3JEy0Q470nhZxjYXp2CPaHLK+osz+gvkb6Nh/KS+CTqn4ruKfryDq3Ennq3RFZgn6sTnOWNTa01YkLg9OLHEd2Njsj1c4i/17+3QKPEzxXWWK4ywTn3tuTfZlmRsDXHlHZEvxjksTf7uKoiJ+oRteBoP4Mu02EOiTzgLH4urqMAW0Rssw06sF8XwGvHKDInOsIr1uE70Hd9UbINpfDzFPJR8vyX6lgWicM4RtaCKJ42vJVeI+vR2bsNN9W3zjWLDB0UXuFNkQK6YdYmn93UKPiQaqEaan0vDmeLK+jS3MPHUdqfYY+JAupK/dp1itUA3REHcWBOn4zhNLOyNGvuKZD+3g2u4O8VY2MEYiJukWnCPE8VrTPwdkkOv6Ds2dWhdfSIr13XI/zg8JTazJn1fje/FAbwr38EVuASP6Mw/Vc4QNaPZAd8tuBzviavvsChkO3C/aGimMY1p/H/xD2IN+YEGJzoDAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\log{\\left (t z \\right )}$$"
      ],
      "text/plain": [
       "log(t⋅z)"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_log(log(z*t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIgAAAAXCAYAAADQigfEAAAABHNCSVQICAgIfAhkiAAABKVJREFUaIHtmmuIVVUUx3/OjI9pgiukIBJyMBsLNAoltLKEtCioPhQREXYrGjCMyCgwg+qDmlnQB7PoOSNhRUqFPUg/hJKSwqSglkGPsXCmtCAz8VF6/bDWxe05+3HumTn3Xun84bDvXeu/91n7f/dj7T0DBQqkRARUgO4GxrAaOAB01FBnGhL3A7lEFEbEuambiVQaRjS2o9OBU8BCh38hEt/dFt+HwABwfj6heRHR3LqlRVDDiMZ2dAPwF9Du8L+DxDfZ4rtSfU/mE5oXEc2tW1oENYxoXEc7kVnwmofzHXAYaPH49wGtGd5fRvo+O0PdiObWrRYkNHSJHcedwGbgEHAU2AUsAkZauMOAR4BvgWPAfmAlUAL69Injfq33vsW3HPkBLkGWv5P6vQLcY/DeAyYAc1L2qV7IUzufbgBbOKOV7dkU4yc0bAv1DliqHfoDWAP8A9yk9huBucC/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Uc6TNh6zaZdHNRF01vB74HDmGHUcSsx3A48ilTQE3Cu0KFChQoMD/BacBWmbGOIo461MAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\log{\\left (t \\right )} + \\log{\\left (z \\right )}$$"
      ],
      "text/plain": [
       "log(t) + log(z)"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_log(log(z*t),force=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.5.2 logcombine-对数合并\n",
    "与对数展开相对应地，是对数合并操作，函数名称为logcombine。\n",
    "符号变量需要满足上面同样的条件。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEYAAAAXCAYAAAC2/DnWAAAABHNCSVQICAgIfAhkiAAAA9hJREFUWIXt2EtsFlUUB/AfVJCHSYnGiEbJF60oG4nxgS90ISuXRom4MCqGDRiixERgoStFrQsNYnwlxQ2iGInER7ryhY+q0QTfCyxqrUAMolGoiHVxz6TT+e58n5rSbvpPmun8z//0nHvm3DN3yiTaooFh9ExgDs9iH2aPU7wLpDUvbyVqmNjCXIi/cec4x30JgzihTtAwsYXpxS+YOc5xL5bWva5O0DBxhZkvdcuTExAbvsQedBTE1H/puBRv4SAOYRfW4viMdgpW4wscxgA2ohP98VPFreG3tSZ+r/TQrs3E6gnbhuDWxP2amr91DoZiPQWewzwsyTk05DvmvuD343E8hM+CewPTKvpNYRvAo+jGN+gLrj8T+yP8pX7oLsRRqdgdJf7hiFXutEXBvVDzt3oj1nklbkn4dOccGpoLc2lw32FuiT8OOzTvzcXBfY05JX669ISGNRdmdiS6q2YhBXrC/+a4Xxf3W43u/Gn4I3Ku4vrweaTCdwbflwvc0FyYp4JbkdHPl57i7hL3dOhvyugvly/M/OB7c0mVcLq0jfuxKnxel4pexZthP63Ezcb32CsVoopD+CkXuKG5MB8H11WT7J6wz6noz8xoO3BEc2GKrqybL2XcH9ph7MSsGl2x/csz6QGjO66KAalz0X74FpUdrLEPVnTFdW9GexQ/Z/hDcZ3RJhfSnCuwXNoyOeyM66K4nos78B421/jMLOXStjAH4zq3xn5qRfdrXE/JaDtwUobfF9ecrYxl0nAs2n11C+27UndcEvcbI/7K4KuYKnX9vowtu5WKmZE7MndpnjHP+O8zZkoktL/qUMI1+FMa0CdL544jUifU4XP8jhsj7qYW2gWheTFnbGguzGXBfRsJFejA9rCtL/FXGXkrlQfcdCMDsT8Te5v6WXaFtGV2G+nQ60K/PbeQwBOh+U0q+okttLeEdlXO2JA/xxRDay8ew4PSkxvG25rfCkVCP0ivxW6pUMU5ZrdmLAuflRV+ofSZMIizKrYPw2dxbjFS1xaD+rYaTYEt0uA9I2dsqP8kuAHvSNU/LLXpevmBOVUadF9JJ8wfpYJ2hv+nGZ/p0uz4oMR1BXfA6MNYgeJQ9n5uMUbOVH3Sdq1DpzR0W3XfMcXZUqJbauxrw37+GMV7WZqBF7XR3a51540Z5mp+283CK5HA0hq/GdK5aMcY5FAM3I1tdDOljt42BjHbYoO0wM3xe4904hzGq1q39ZW4x//7R9U83C2d1oek77m6A2CBBbhXGiPHHFfjNWlgDkmvzE9wl+YPzrHECqn4B/C80Z8Dk5jEJCYG/wA7jBWQC6C73gAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\log{\\left (x y \\right )}$$"
      ],
      "text/plain": [
       "log(x⋅y)"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logcombine(log(x)+log(y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEUAAAAYCAYAAACsnTAAAAAABHNCSVQICAgIfAhkiAAAA7VJREFUWIXt2F2IVVUUB/BfjpmjwggRKVRcbNJ6qEGKKNOKmqdeigjJl76MIjKkoAcN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fkezzj1pG3KE93TYmZqkK+DS8lhJYXDNuqrj3bDxyqR2ETtHF64/GZKvE4tak//vE945hvC6Uvg4X4z7j/5GpFZyF+4VsHHFcjjeEOO4Xv3ptwd2qXx4nMIEJTOB/j/8AWez08vEDpFgAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\log{\\left (x^{n} \\right )}$$"
      ],
      "text/plain": [
       "   ⎛ n⎞\n",
       "log⎝x ⎠"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logcombine(n*log(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEYAAAAXCAYAAAC2/DnWAAAABHNCSVQICAgIfAhkiAAAA89JREFUWIXt2FuIVlUUB/CfM17T+ISIJoj4kHFE8iE1ultBWlTUSxHRg2CBUBRRdMF6yCCyC71Z0AXSHiYDZSypyB7CSClLLMpMiNTCMacCTcO8ZQ9rHzpzZp9xGqecYP7wsWev9V/7rL3O2muvM4xgyNHEcSw7tW54HT2YOAjb2WIPdw6lQ02nPjAX4E88cBJrdGE3Jg2JR4ZHYNZiLyacxBoXin08OiQeOfWB6RDZ8vIQrLUVO9FaCFoqhHlis0swA53YgwPYgIv+wcNuxUfYh4P4CoswLsMdhfvwDf7ALixFAzvSr4o7kt2bGd36tI+637oKfwXOxdxCMLpCmJnGDnyGD7Ac5+F6vI127M84U8ZTIgi/iOAewHVJfq14AUdK/BdwF7pFBhzGTSLNx1S4BebiGD7J6LqS71UsEAH4sCJfn8Z5eD+3oRUioj2YVdGtSro5ad6UP0qXJPkPaCvJR2ONvud5TpJtw+SSfKzIuOP6ZsxEHBVZOFA8l9Z6Td+T0ki6jXXG2xLhhozuyaSbl+ZN+cC8kuQLM2t0iLf8fUn2auLPz/Avkw9MR5KvzW2iglF4MfGXpnkOB/FTTjEpOb2zxrgzLT4lzZvygdmU5O01DuxM+skV/pQMt1Ucox0VeZGVufpStV+euM+cgLtLZCF6p9T5ab42LVTFLFFIt5/gAY007q7R767winFPhnsMv2bkB9M4vh8/xojSMB+L8Ug/XOLKL9btFZiipmzKGJ2OqdgsH7Qy9qWxrUZ/doX3WxrPynBbcUZG3pPGnI4IWBduwYN4os7ZhBaRwT1lQYHiRvo8YzgzcXNBq2JzGq/K6Npxjsi6vRX+5Rn+xfrenETW/YxpGd1EvCNu0bvx/AB8nibKxxc55Zc4JG6DKu4XmXJ7SdaUrzGXJvl2nFmSt2J10j1Wkl/p71upUZKPFf1GrvjCSn1rWUNcvUfli3kdFqS17ikExdsYh+ni+jucMZydxoFkzAY8i4fxtdjA76KPmYGPxdVZYJ3oXRZii2gLjuBGcdy6RYdbxSrcLPqi75KsU7yYjaKYL87YLREJUMY1op69VSUXX5kv1Wx2q2jqykevqf9PgttEEPaLbnaLyJRcwWwRWfltcrpbNH2NZJ9L8bHiev20tMZ+/Xe8uQLfEEV3dc0+hiWmig29UaNflPQza/QDwb16N67DCm36dqOniSJ6XHx35TBe9EVrBvncCSI7Vw7S/l/H02KDy9Pfy/CjCMq76rtVuAKPG9w/qqaLOtQchO1/gqvxnriGD4livRkPiUZtBCMYwf8TfwExowG+L72oBQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$n \\log{\\left (z \\right )}$$"
      ],
      "text/plain": [
       "n⋅log(z)"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logcombine(n*log(z))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEQAAAAYCAYAAABDX1s+AAAABHNCSVQICAgIfAhkiAAAA6RJREFUWIXt2FuIlVUUB/CfMzo5TTBCRAoRh2FSgkKkiLKsqLEo6AJF9GRYYBRFFF2woOylK71pDxU09mAXEi27kD2EkV0GwqAMg0q76JQVpCZmadPD2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OKR8TEVqbvg/hOLMYbDnWWOZyLB4z/H0St4mShR7UJHgdciDfFdbpfiPAm3CWaq0lMYhKT+N/ib4G97Zge9JoEAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\log{\\left (z^{n} \\right )}$$"
      ],
      "text/plain": [
       "   ⎛ n⎞\n",
       "log⎝z ⎠"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logcombine(n*log(z),force=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.6 特殊函数\n",
    "重新定义符号变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "x, y, z = symbols('x y z')\n",
    "k, m, n = symbols('k m n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "阶乘函数factorial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABHNCSVQICAgIfAhkiAAAAO9JREFUOI3l071KREEMBeBPUbTYfQnBn2IF91qIhaUP4tP4HIIsNjaWdlrY+FPYWFiIpVYubCWIFjcXZi+5woKCYCCEmUNOTpIZ/qB9hoP5n2b/dcJ9tfxDDDDCCya4ws6shMOIa7hGD0e4wC7O0J9F8UkofEXVwk4D22vdTy1loUPhAe5a2EPE5e8IS+vhA8+YS/BRJK607sd4yxRuqWd63lGxiuSnhDBtuZnZbULWxyouk2Lj8lASNvO7SQiHavVZsc3yUD6bCu+4T5K2I7YXBRvhU7YUZJkCOFa3up5g6V8eYFHebqNwgscO/D/bF0c9M2JzlRy7AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$n!$$"
      ],
      "text/plain": [
       "n!"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factorial(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAABHNCSVQICAgIfAhkiAAAAg5JREFUSInt1k2IjVEcx/HP3EiYoVBmokjKSzQXTTIpxSxYjcaSIisWysLGRlZTSikrykbZCMmkZGkjmzFYYGpsvCREGeMtL2Nxntsczz3P4966C8l3c+7zu+f8f8//nP855+EvZikmsRM38RFPsLWVJnui3/2Z4S30YTmGMJIYtx3zmjU7gg3R8zGMoyvS9uJ5YuwMnMH0/B+VArMqlmA40rpxHS8jbRnGEuO/4gqOFsSv40ZmEDOGQzltCKdK4oxgQSykMtyMTtyPtHYhm/x6rUtoMVc1kOV5nMxpvfiRGdeYLxTR2pJYvXgrsZY12rIOu3P6QTzOaX34gmklhrOzFy3cOquFt15TEqRZRoUKR/0arsraVy00fI2VRYaLs/ZDCw3Ho7h1hu34JqxNq3gvKra84aRQOEWcEPZoM1SyuEnDCaHqZhYMruJek4ZzREuUN3wWdUrRrXyjp5iLp0WGD7O2Sz2dWGgqww5cwl3h6iqiM4qb5A32JfQdwtRUhO3zCBcUTz8hu5/CiYP0WXpNOCPzVPEAu3AbZ4X78nOJYVW4Xe6U9NEjvH2ei3gnlPmWsgARgzjeSMfL2JjTRnEOnzDQQIyKUGAdjRiuyILXmCUcwj3CNE5g/R9iDOBwI2Y19puauk34bqpABvECiwrGtuO04i+KQvqz9oDf17VN+IQYFrLPs024mv7zD/ILr5JeeAAM8ewAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$${\\binom{n}{k}}$$"
      ],
      "text/plain": [
       "⎛n⎞\n",
       "⎜ ⎟\n",
       "⎝k⎠"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "binomial(n, k)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "与阶乘函数密切相关的伽玛函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACYAAAAVCAYAAAAq05ytAAAABHNCSVQICAgIfAhkiAAAAdRJREFUSInl1b2PTFEYBvDfzPhYGclobaEQNtERsgmJbvEH6CWoJDRUokDjsxWFRijEhs2u0FgRkdjEimgUGgqF70QkiiWGUZxzk2vmzuyZe1U8yc2dec/zPu+Tc97zXv5hXMVHNEvkbkYH+xcjdhKeVTn+FvzC4RKmMkzjHVbmg7UCY3BygNAZfIu/ZzGO1VgoaWwc8ziGU/1I2a6kYEzYrUslDeXxAq/RyAL1CmL7hB2fLFibM7gdHnbxr2MNJrLAkgrGJvATjwvWpnGvIL43GnjQFZ+L7x24W1Qs9SibaON5AjfD+ah9We9JteLak37JqcbGIm82gVvDxci/oPfCZVjA+6rGtkZeUX/l0cCVyD27CPeNcAqVjG2MvFsDOEtxI/KOJ2h+xteqxkYj71Gf9RHciZwjCXp1YfS8qmqsJnyGPhWsNXE/FjqQoAUbYt2pqsbgZuSuy8VawtVvY0+iDmGMdHAwC1SZY1PYjV14GWPXsE249mtxoiDvNL53xXYKM7Fvzw6zY8uE6z0f/9eF5h008T8U6LSEUTGTWDcJR2PBTRU0DkWN7X/FUcSI8PG9XTJ/Bd4K/foHGr3codDGMyzHU/wYMn+90G/n8KWil/8cvwFRLocGRd1b3AAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\Gamma\\left(z\\right)$$"
      ],
      "text/plain": [
       "Γ(z)"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gamma(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$${{}_{2}F_{1}\\left(\\begin{matrix} 1, 2 \\\\ 3 \\end{matrix}\\middle| {z} \\right)}$$"
      ],
      "text/plain": [
       " ┌─  ⎛1, 2 │  ⎞\n",
       " ├─  ⎜     │ z⎟\n",
       "2╵ 1 ⎝ 3   │  ⎠"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 普通的超几何函数\n",
    "hyper([1, 2], [3], z)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.7 重写 \n",
    "特殊函数的经常用到重写函数。重写的形式为expr.rewrite(func)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADkAAAAnCAYAAAC1xOBuAAAABHNCSVQICAgIfAhkiAAAA4JJREFUaIHt2EmIHUUcgPHfJIImCGrckoNGEATFSVQiBDUBdw8KEogLaED0ouakInoygiISPEQkIl7akyhqcEFNVIi7oDKJiILLSVzGRFEJxBjH8VDdmZqaXl73vJlH4H3wmFfVtfyra3vzMWROOQU78RV2Y91Ao5kjlmFl/v0k/IDFgwunNzK8Nov6X+DUKH0cxnF6izZewF11Be7Hp/gLe/Aqzm7RwTE4tkX5mFX4GiNR3mY807KdFfg9j6WU7bhFGNgotuEXLGnZUVuOF/blBVHeYvyBNR3a+xx39lr4aEzgmjy9TlhS+4W39S5Ojspnpi/XndiKR7AXvwqzsyAqcyTew81J3+vzPkZK8g9geZS3Bd/ixDz9AD5sHF3OMkziQizFP7gbpwmzfZvmQf6Jh3EGbsC/uDF/PoJnsamk7y14qyR/BJ/h6Tx9j5n79qo81kX1wws8hzEsxHnCgJfXlM/MHOQnSZm3owAvwn/YFX1G82cvq96PV+Ag7hPOj1XJ8xV5rIcGfkRFQ5uxVtgTE8I99g6+zAPdgReFJVjH7iT9o6nZ/8D0pRtzFP6ueLZDOCAfwtXCzMbsz/8emsmyTh7DBlyK7/K8CVwuvMVduBXfmLrnqjiYpCcr+kzZK1whZVyS97tA+UsuDso9RUba4eO4CRcLJ14a4Md4EOfjJ1zfQ8BdGMNZJfkr8RLuwCvCfk8ZzWMbLzLi5bpVGOC1wsm2NM/fJxw0lwnXzDjOFS7u9EX0i+14FCcIs0o4D143dX+OCatqDd6P6q7Fm1UNT1Z8NuFMvCEM8ICwjO9N6mdmHjxPNJSp4yNszL8vEX4sPJWUeV7Y2wWLhMNodY99DJwrhX2/sEWdjcLBNI02Dcw33wv34s/CfdsL5+BJ/DZXQQ0ZMmT2FL/yJwcaxZDBkOmmObrojCYadUdXumqOVGfMVrfQg+6YT8p0Rr90SyvdEVOnOjLtNUeVzohJdUtRr6+6o6BJdWTaaY4isDKdERPrloK+646CJtWRaac5qNcZBbFuiWmtO1LK/kuPVcc23C4Y7jrqNAf1OoMp3bJeWLIxse64Tg+6I6VskF1UR5PmqNMZZbolprXuSKnyLf1WHVU6o0630FF3pJTZutX6rzrKdEadbtmnT7qjiibVkemmOWKdQb1uOWx1Rxed0USp7kiZT/3RRWc0MdQdQ4YchvwPPWMfUNoUjTYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{2 \\sin^{2}{\\left (x \\right )}}{\\sin{\\left (2 x \\right )}}$$"
      ],
      "text/plain": [
       "     2   \n",
       "2⋅sin (x)\n",
       "─────────\n",
       " sin(2⋅x)"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tan(x).rewrite(sin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE0AAAAVCAYAAAAD1GMqAAAABHNCSVQICAgIfAhkiAAAAqVJREFUWIXt2MurTXEUB/CPS9wbohiIugN5lsKlkIjyGBL+gIuJCQOZKAMmlJEyEBOPJIq8ysDk5hl5JAYGyCW5XnnL2zX4/TbHufvcfexz3HPFt3brnPVdv7V++7fXb/3W3vxHTbAHT9C31hOpMiahHcuzDNvLuAYW2E/GN6yu7nz/GJZgK87gtXA/ezuxP4w29CtU9iphvKETRx8Kfm+MwbdlTLa7YB3G4y0eYEyG/SZcxCrhXlORZFM5GCVk2Y4y7auBZmF+s3KOn42R6BF9ZGUa3MQ99EwUdTmDw7IY/EAKNzdOaBPGYR8eC0/4PKZUELcStOCW8hMD9qMRcxJFJYs2B19xIYWbGOUoXBJqwm6cwjQcQ/8KYnclzkU5N1GUqmlZ6IsJQuq+S+GbopyB6bhawB3Cojj+TM74XYlLUc5MFHkzbZiwx9tK8EmmLfXrghEWGupzxu5qvBIOv8ZEkXfRBkX5IoXrhxG4jxMp/PAo72TEaNWx3dkZuZYUbldZM8+H5xic/Mm7Pd9HmZYtE4SHcVJ6wW0Snt7djBhb/NoTJr4XCPWxtYi7luGvEjT4ec8dUG7LMTTanU3hVkVuRQrXXzg8WsqIkYZmlbUchZilvJajTmit7hQq8qANTzE6hUvq2eUSXB2u5IxbC4wWWqsfmZx30dpxWtjnI4q4JnzC9ZRxk6IsPhy6M6ZG+WN35K1phNZhMebjdtT1wVjcEBauGMmi1SrTFsYLhkQ5zc9D5BnWFI2ZJ5SUo6Wc/s5rVG88Et7NEiRfBraXGHMTb+TP8GaV1bT1Ov8Y0VpkP0A4AI7kjJeKtTHYxCzDvxQrhfubUU2n9cLL7PFqOu0maMBDHCwmena0/S18EYp6H+G0/Fyhv+6EkfiIzXhZ47n8xz+J72P5nJ8iSqSSAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\Gamma\\left(n + 1\\right)$$"
      ],
      "text/plain": [
       "Γ(n + 1)"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factorial(n).rewrite(gamma)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.8 expand_func"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALUAAAAVCAYAAAAAT69HAAAABHNCSVQICAgIfAhkiAAABF9J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8Qf3po7VL6ba2IRM8zeBlWqsWwV8l5NwUNk7AuWzIaE+Tf2B8t2rseVpEIM/1K7Blyp+FPMzdBom/j5bejH6Jbe2LuSny3Hg5YztigrarEm4U9n2BMpnQ0JtF/QdZDFVRFbUJeRrqzyWt9d5ClmIvKSx6TSIxR9q0+B9FTuJ7Ef3aY5EE2fi79PUMfpFW1sHsh3yN/CqJqi8uX1RY2tVsZcC5bMhobam7sO8ezCmiVmCLELyZousBjH5Q20a9GHfQfkhE2Pj79PUofvFVlvV+EKd9PXQiWcJPsI+s85nDVz4+yCkVqFrm0Ib8oeSodCJZwHakX+0DVr85qsGrvx9EEqr3Np0/7ryxSTwM7AQWXw8DZBztqATeALsQ5758jBfNXDl74NQWsWorYEGGmiggf8F/wFZNCWl5i7fHAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x \\left(x + 1\\right) \\left(x + 2\\right) \\Gamma\\left(x\\right)$$"
      ],
      "text/plain": [
       "x⋅(x + 1)⋅(x + 2)⋅Γ(x)"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_func(gamma(x+3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.9 hyperexpand\n",
    "将hyper函数用标准函数重写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJMAAAAXCAYAAAAPxH3bAAAABHNCSVQICAgIfAhkiAAABJ5JREFUaIHtml2IVVUUx38zo9NME1whQomIU+lI0EPRB1lpY2lRkRVJRA9xLRgoiugTrIemF/uQINJ6qKAxwgq1DCvJHsRKKaESyizKvBbO9DFBZWIf2vTwX9Oc9uxz7jnn3nvOCOcHlzuz9lpnr3XOOmuvvWegpGQSEgCjwGCxbvAC8CPQU7Afk4kz0bO5uWhHkhJQfDKdBfwD3FWgD3mwGFgBvAf8hu77i3VsXgOGgW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xsT+9TCYg+I34lcjxJnP2qEd6KK5Gua24E7gS+Qo0PoILNi9r4GtRNteT/M6L+Pdpsvbufl2ygkoUr2yjRQx6eax6aCGu/1jvxss3H/ON7K2CcFs1AQL0WML7XxM3Lz6MjhdnRv5jryZSY/KXePcmIGEzcHR6NGcBT9nc9HF9odbmida0ck3ai6r/WM7aK1RxGF8whKilX28yDwHUqkt4g/cZ4HPEj5z3FhTkVLY1CsG8VwMTrzGEY90wF0ZHAvOjwrKSkpKSkpKcmTfwHcJX1LZoi2uAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$- \\frac{\\log{\\left (- z + 1 \\right )}}{z}$$"
      ],
      "text/plain": [
       "-log(-z + 1) \n",
       "─────────────\n",
       "      z      "
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hyperexpand(hyper([1,1],[2],z))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.10 combsimp\n",
    "简化组合表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJEAAAAVCAYAAABG+QztAAAABHNCSVQICAgIfAhkiAAAA5hJREFUaIHt2k2IVWUcx/GPJumgYjAugqBFpBG0aMbIWgTTi7kKgtpGRC2CKKKCSIjCjdImwlUtwqKihWIvIOSmFyt6M6SiaZE0tXBqEssKLLWmxf+54+XMeb3eO9d7uV+4PPee/8tzzm/+z3me85xhxIjzhJcxh9X9PpEesAnzuLeG77Dq0ESDjrgG/+GRXnXQRcZxH/bhe5zECXwoBFpeELcPs1hTknuQdIA7sQsH8YcokldK/Oto0DEH8DvGepG8y9wvxDqKV7EDL4rzn8ceLMuJuzbZt5XkHiQd4LC4pj8xrbqI6mjQERvF6Huh24l7xE24zeI7zsX4SYh0R0HsNH7EBTm2QdMBbsQGMWimVBcR5RossCUl24Gr8Bp+wV/4GJsz/juT/81dytdPtolz3VVgfyrZt+bYBl2HKfWKKFeD7IicSO1GfC7mv5fwPq7HW1jb5n8L/sUnBZ02zddPTqf2TIH9o9RuybENkw5llGmwwOui0uYwmbHtTbYb0u/VQvCvu5Svn6wQ11F0p4F1yf5Z5vgw6DCl3p0oV4OiO9E9+DJjm07tqtReIubG2ZJOm+TrJzvFNLMf7xT4nMDfuDRzfJh0qCJXg/YiWoPLxQJzf06Cy1J7JLXjqf2toMOm+YqYEdVf91M1mrI8hEfxHe6q8D2O9ZljS6HDjN5q0IRFGqxo+361KKoD6USyTIpK/CH9PpnaohHUNF8RR0T11+VoA98H8By+FYvi4xX+Y85ed4ul0KGXGjRlkQbtRdSaqw/lBK4Vj4MfOCvEXGrHc/w7yVdE0RPPufIwnsU3qY+5cnfLcZHFf+yl0KFXGjQlV4P26aw1b3+REzyRfNuFmMWvuKKgw6b5lpLHRQEdFvslVQVEXOeyFNPOIOvQlFwN2otoEqfwVU7wptS2LwrnxQhaL+b8LE3zLRVPioX0ITHCj9WMuy6172aOD6oOnZCrQWs6W4krxWPqqZzg1sVmR8xescO7VbyLatFpvl5zN7aLPZ2DYlGdZQa7c47fmuLezLENmg5we/oQO/bEntXu9P0YHsvElGmw8Jb2+YIOp8U7luyWwIX4GZ92KV+veVr1k817OXHrxGLyjYK8g6YD1VrMZPyrNDgnnkidTlQ5DjAPqt4QHHYd6mjQMavES7m3e5H8PGBMPDLvqfAbZh1KNSh9G1uTM2JhuFI8gZwudx84NuAfPCP+1aOIYdahrgYjRowY0Sf+B2QCUYxmCAjSAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$n \\left(n - 2\\right) \\left(n - 1\\right)$$"
      ],
      "text/plain": [
       "n⋅(n - 2)⋅(n - 1)"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n,k=symbols(\"n,k\",integer=True)\n",
    "combsimp(factorial(n)/factorial(n-3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACUAAAAfCAYAAABgfwTIAAAABHNCSVQICAgIfAhkiAAAAc1JREFUWIXt1z1rFFEUxvFfJJXGSkQLi6A2Wri7jY0Yg/gBRC1E8wEUbGzFwjaIhVbahCFdxNgoBMHCykLxFcUUEUSIdoJE8a2IxR3x7mVmM5uduBH2gctw7pzD/ufMnXufZSAwhjv4gGWcSBM21PRDGS5VzN2EFzhXlhBDjQrkR3EPX/EWh7tn7Kg5XMTtKlCN/Hoel/P4Na7UDLWiUqglnMR9LGAWW/sNdRcfo7mdAlyqC/gSjdMFcwdXCzWcQF1N7rfwrKDuOm5G8SQWcS2aW+wVakToSgrQwq2Cuk/5+KOlPC7q6qqh9glf3vPo3hbsKADtVSPYHcWjaAoP9T5OPIv5pPgIvmt/xWXKVN+nxoUGpCOrWD/Q+tZQfl3uK8X/qEnhwOyrUuvS1L5X1a0VvVQRVEP3m2WmRi9F+8a4Hdv87dRmTGEXjuFdZcxyzamwPOJOtYTTfQF78Ag/cKAmoMqKoZp4ieN4iBuYwLd/CZRqRjgUP+NQh7zUN/3CT917qdKFHq+ppuCbTwkOoUxr6qViqI2CnZjAA0wL6+hpQc2aeqkYqiG08xUeY6+wn+zX41Mnquyl4AzeRPGQ8KfhidDFTsoMvNRA61y/AXsFed5+ObVOAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{n + 1}{k + 1}$$"
      ],
      "text/plain": [
       "n + 1\n",
       "─────\n",
       "k + 1"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "combsimp(binomial(n+1, k+1)/binomial(n, k))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7 微积分\n",
    "主要介绍如何在SymPy中执行基本的微积分任务，例如导数，积分，极限和无穷级数。\n",
    "## 7.1 导数\n",
    "求导数的函数为diff()。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAAVCAYAAADhCHhTAAAABHNCSVQICAgIfAhkiAAAAwdJREFUWIXt11uIVWUUB/DfaJqjiUUWJF02aFIvSRTRQz0EUiIRUU+9iYKEXYigICF6i4jMoIegC1gUKYwoBBEDYUaEeSlByidDKZzQ0nmpqZw6PazvMNt99p59mPMFDswfDnvvdfl/31nfWmuvzRwuaRToYEdGzg9wBksG4LhD7GtTlh1lQCFvoO7Ev3g2A9cejOGKDFwDYwFuwXWZ+EYxjuEMXHeJQ9yageuSwmqRTW9n5DyOU5jfFczLSA4P4XORun/hNPZjS8Wu0Ft6ZVmBnfgVf+IwHmxYcyOGsKtBP5p4H6nIh9JaHbxS0e3EjVjbwDkQNqdFx8Tpvox3cRCHKraF5kDtE035ALbjfRGsf3BfzbqHMam5ia9Jvj8oZQi2pfXqMnFt0r3WwDkQjogsurZGt7zyXGgOVAcvVewfSPJPK/IlIkjHWva2I/lvSM9b0/Mu9VW1LOkPtvDOCEfwO67qw7bQHKiTLj75Lk6JUixjdfIZbVnvekwk7ieTz2dYOI3PBH7pPlSjedLUqfbz+7Dk+xEW43tRMg/jmpY/UIejolSq+EnvIVydrudbOH/GG7gJb+Jr0bP+nsbnnFIlXFZRnhD9oF+cLt2/Lk58C57GMyKY+/Gc6CX9YLxBPqn3YCfSdVEfvGdL95vwR4v9cIn/f8OVWI93RHb85uLeVZj+rVeHL5K+jBVJ9lXLfh4TI8RYsn+rxX5esj/RYpcV74nNPVqSFfIEaki8Ic/2WE9hvSixY6IVHMcFMfA24da01u6uIOcctU5vKTOVSW2pPhN08KXoJatq9PdgRPSo+0VAXxT7rM5OZdydrvuy7bSEcfGWGBHzxzbxeu2I/rSgZFvIk1FEWXXwREW+Ju1pDCsrukPJ596GtT4WPfGGBv1AeFx8UP4osuccvsPzWFqxLeQL1EJxQN+UZKuS7Dxuq/HpDpQHanTLRBPf27CPWY0XxB+/PQPXU6bPtlmNRWIg/WRAnmEx8oxUFXUT8GzEJL7F5aIfXpghz83iM+xVzfPcHOaQAf8BRM7YrhpirqMAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$- \\sin{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "-sin(x)"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(cos(x),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADYAAAAbCAYAAAA3d3w1AAAABHNCSVQICAgIfAhkiAAAAqlJREFUWIXt10uIVEcUxvHf6PjK0lFRfMxCFxISB3wgBHUxiorgJsaFi6CSIIJRxAeKEnCnC8UEBTGC6EJEEeJGlOBCTTIEFIwZfKEJ4lsZiAZUnKiTxSnxcr3dw0y3NpH5w6W76nxVderWqVN1+X8zEqdwCRfweU29qSLD0JT+D8EtfFQ7d94df2AU9KqxI9VkIvqIVftgaBD77LNaO1JN+uEMvqy1I11hPp6jMVP3Pa5hMOpwEJveu2cVUodz2JPKa/AAo1N5Cl7h98zzab6TBnyNH3Edz/AYv+ArtUs0M/Ev1uMfkSS6xFJ04C4OYDP24lGqPyLeYC1owQvM7k7jZsz19soMxU0xuXmVeNdNmvFEhNz4ane+QUxsR67+p1Sfv8rUYV+ybSnobx6Oow3tIhlsQO+crklEzEIcTW2qytrk5PaCgV+KMyTr1Lak/yGn7y2yWIeYzC58h6upbn9G24g72JjK48SqTa1sKm+oR2saeFaBfV+yLUrl16t7yNthvTPZNqd+X9MHvybbxxiIy9ida39YJLOqsDUNeKyEfYTIoDfwTdKeQN+cbrJ440dL9LMktV1cmbtBfSf2FViNK0qf7LdFOK0Xe7BF7Ln2nG652HtPFR+on6Tfd555l4k3eFFkxnKsStoOjC2heZjRlHtmVOp4OVamQVrFd045FogQu5fa7CrQ9E+201X0scusS06cx6BOtHNEyLWKu9tlcUvIr9oAb1a/JnybHDgnMlM5poj98pf4koUvUvuiBHFB8ZmX7S9/jnWb7EZdKFL3S5EEHhfobyRNkwirZ8mhPzOas+I+Nw0/Z+pnisxaj5Pia7cXhmOCSPmjKppNCTbpfGOfwhjcx9/i0MwzI2l/K7BNEnfO+yJk20QY78b0ak2khx566KHb/AenHK4CTaz+KwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$2 x e^{x^{2}}$$"
      ],
      "text/plain": [
       "     ⎛ 2⎞\n",
       "     ⎝x ⎠\n",
       "2⋅x⋅ℯ    "
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(exp(x**2),x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "diff可以通过设置参数的形式，可以求多次导。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACgAAAASCAYAAAApH5ymAAAABHNCSVQICAgIfAhkiAAAAehJREFUSInt1U+IzVEUB/DP40VjJUoUu1mwYGKhFKXJpJQUNhZCZqFokpJS6mVDjCgLspCNhVKmUEKSP2XxFmoyTKHJAguFhI1/i3te8/Pm95v3e9NYkG/96nfPOd9zv/fce8/lL8Js9OIKnuMrPuIBdmJKiRxb8TO+3skWuCsSv8ZFHMF5fAj7ZVTG4S+I2E9/SmA31htbqbl4FZNuKuBWcBsvcHwyBWbF3MFV/GiKeYuz8b+6IE+ftMAd+NxizpvSAjY22Su4EL6jLXKMwf4gnszxLZLOa8NXM34Fu/AdQ5iasZ8I3rl2xVUxGOS1Ob46htFRUiCjldoe44MxvqTcZfwN/UG+nuM7LFVjRcZWRuB8qeoj2BPxNzCtXXF9QX6KWU2+5fiGY032MgJJXaLRkh5iRrvidgf5iXSTs6hK2zqE6RMUuC8jcGG74vYGcRBzcvwzM8lbfady+FukbvEmYs4UCclrvAeka/4YPXiXE9OB0wU5l2Gp9AIN45Z0+BtYh4HwdeMeOrEYz4qENnBIWlHd2DNXFjXFW7wSX/AS88K2OeIH8pJVM//bjN7K+9IFacaI1CImgi5ck973Hml7SU9oHRuwKubORU3r83S3hJBGnmwFO6UX6T2W5HDWBOdRifz/8W/hF2Y7j+4N/qziAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$24 x$$"
      ],
      "text/plain": [
       "24⋅x"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(x**4,x,x,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACgAAAASCAYAAAApH5ymAAAABHNCSVQICAgIfAhkiAAAAehJREFUSInt1U+IzVEUB/DP40VjJUoUu1mwYGKhFKXJpJQUNhZCZqFokpJS6mVDjCgLspCNhVKmUEKSP2XxFmoyTKHJAguFhI1/i3te8/Pm95v3e9NYkG/96nfPOd9zv/fce8/lL8Js9OIKnuMrPuIBdmJKiRxb8TO+3skWuCsSv8ZFHMF5fAj7ZVTG4S+I2E9/SmA31htbqbl4FZNuKuBWcBsvcHwyBWbF3MFV/GiKeYuz8b+6IE+ftMAd+NxizpvSAjY22Su4EL6jLXKMwf4gnszxLZLOa8NXM34Fu/AdQ5iasZ8I3rl2xVUxGOS1Ob46htFRUiCjldoe44MxvqTcZfwN/UG+nuM7LFVjRcZWRuB8qeoj2BPxNzCtXXF9QX6KWU2+5fiGY032MgJJXaLRkh5iRrvidgf5iXSTs6hK2zqE6RMUuC8jcGG74vYGcRBzcvwzM8lbfady+FukbvEmYs4UCclrvAeka/4YPXiXE9OB0wU5l2Gp9AIN45Z0+BtYh4HwdeMeOrEYz4qENnBIWlHd2DNXFjXFW7wSX/AS88K2OeIH8pJVM//bjN7K+9IFacaI1CImgi5ck973Hml7SU9oHRuwKubORU3r83S3hJBGnmwFO6UX6T2W5HDWBOdRifz/8W/hF2Y7j+4N/qziAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$24 x$$"
      ],
      "text/plain": [
       "24⋅x"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(x**4,x,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "diff还可以同时对多个变量求多次导。只需要按照求导顺序设置参数即可。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACgAAAAUCAYAAAD/Rn+7AAAABHNCSVQICAgIfAhkiAAAAeRJREFUSInt1U2IjVEYB/DfNaYZCwmJUmZBZAj5SE2Ur24WViZWarKxU5osNDcfO0tkSrKyUljMRlJKClnYoGkIG1+DpglF+ci1OEdep3PN1Vxuaf516j3/5+P8z3mec17+c+zAJ3QUuBN4hFl4jt4kZkWM6cQBVDPjcKMElnAHZ+J8P15jfpxfwLkk5hr64/dUzCmM4xjGgkYJhDK+CKfxHqsLtl48Lsy7MYqZmTx9eIlFjRT3A7fwFVsTvkso2Qy04Qn2ZeIreIGF9S7YjcsYwWehp/rQkvHdhA/4hpWJrU3ot7Jwwg/QmvgcxDN1lrVF6JlqFHVK6IuHkTub+C/HW/RgIG4qxW2cFMq/LbEdwlM/e3ZM9EchRzG5wLfiZrR1Rq5DKEslzpcJp7g+yXks8lcSviJUqMuvF6W9lri1MdFADfueKHC30FNDOJ34nMeNhOsR+nNJgSvhnfwTs7EYXDylvTHwI45kBC4tJB/F4ozPzgy3K25ksMBVMS3j+1u8kd9ROrbUkWsSZgsXaxjT/1RMiva4+PXxJorYILTLkNBj48YUQeDgWI7NxF1B5PYa9nXy7+BfRanwXcYl4eJcxT2hl+ZilfDUzPvXAlOswUW8Ev6vI7gv3MLNTdQ1gQk0Dd8Bqqt0b5Kv4Y8AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$e^{x y z}$$"
      ],
      "text/plain": [
       " x⋅y⋅z\n",
       "ℯ     "
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=exp(x*y*z)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ8AAAAaCAYAAABo6FFLAAAABHNCSVQICAgIfAhkiAAACqlJREFUeJztnXvQV0UZxz8vl5SgLOiCklKhmZpAXmIiwRcyTKnJQmxwKo7RdLMLCRaXIX/ZGGQZGCSSjb2W0SgkVlIJlBlRjjFqkqBZ9JYVoBQJJXHJtz++e3wP5z2XPbffBfYzc4b3d3b3Oc/us+c8u8/uOYDD4XA4HC3G5cDDwG5z/BqYWILc2cBvjMyngB8Cr0sp0x84vuB1q6pPFXKr0vVwIU8fapTcqnR1HBm8ttEKNIJ3ABcCJwGvAa4BDgDDC8q9G7gM3YCnA6uA7cDAmPy9zLX7FrxuVfWpQm5Vuh4uZO1DjZRbla6OI4PhwNRGK9EM/BP4UMkyBwD/A94ekz4bGF3yNX2qqE9VcqvS9XAgrQ81k9yqdHUcvnweGFmivMnAPmBo4Nz1wOPAS4G/AleEyow0ZU4FZgFdEcdVJer4HL2BKcB+NHork2OR4m+KSBsErC35elBdfaqQW2Xb23AxsBhYj0JHXcCtGWW8l+4O+oFStRNJfajZ5Falqw2dRD80utBsLMwgZK9VwB+AvcDTwC+BaSgq4ejGtp9PBNagh/xeYCuwAnhjTP5jgbvKU5M2YCNwk/k9E9gBDDO/VwDfDZW5B1hi/n4BMDhwLAK2ASeWqCOnA/8GDgK7UCiobG4DHkQP2TDXAh8t8VpV1acKufVoexseQjfTHmAL2Z3P8cC/TPmqnE9SH2o2uVXpakMnskUt4pgZkf/DyGZ/B74DzAduNjK6gJXoQeaw7+dfNOk7gW8AC1A77geeBd4TU2410F6eukxA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bQeGhNIuQE51L9FfEhiNvngSXk75LT3XzIKcQwO+puErOQJNU58G3oKmwaCFqI0o3jkGed28bEC7KgageG1aLNiG9ajRXgX8KXC+FeuzHHWe+9EiYy0iz3y0ztVsXGQO0JZK0O6eDvP3TqI/zWJDPWwJ5dqzVW05Gb07dw+6n/ag9zQmovDNj1BYKMhUund0rUebDcJ00t0X8trTxj6t2u5BVqKw4nloNuh/4fwU9C5NG7LRPyLK+psSDobOX4l2HX7PyH4Yrd0MAc5E62MnlFwPK05EldtF9IuR5yGveV/B64wxcu6n3G89LeXQXRqtWJ9edH/vKe7YUfAaSXgUG9nVSNa9M6Mcf0RYL1tCefZstC0hvz3PRS8iPopeMDyAZhlr0Uwiql1qpK9p/NzkLWLPNPtU2e4e9Zv5gJzBdNQOu5EzeRI57QkxZUDOJe49v7ORY9uO7LoThTyXoY0hhzU/QKOjs0uWO4Tot2+rpqr6OBqDs2dz4+yTzCD0hRNHCH+RcElaxpxcQ33/E7Wq6+OoL86ezY2zTzqzacx/wdGUnIBikzehGOvvKOeFwCj6os/NVPl/h9SzPo7qcfZsbpx97BlG/NbsIxL/kw270KcZjkvOXphB6DtnVVHv+jiqxdmzuXH2sefMRivgcDgcDofD4XA4HA6Hw+FwOBwOh8PhODL5P/Qh3MlmUxVaAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} y^{2} \\left(x^{3} y^{3} z^{3} + 14 x^{2} y^{2} z^{2} + 52 x y z + 48\\right) e^{x y z}$$"
      ],
      "text/plain": [
       " 3  2 ⎛ 3  3  3       2  2  2                ⎞  x⋅y⋅z\n",
       "x ⋅y ⋅⎝x ⋅y ⋅z  + 14⋅x ⋅y ⋅z  + 52⋅x⋅y⋅z + 48⎠⋅ℯ     "
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(expr,x,y,y,z,z,z,z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [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trTxj6t2u5BVqKw4nloNuh/4fwU9C5NG7LRPyLK+psSDobOX4l2HX7PyH4Yrd0MAc5E62MnlFwPK05EldtF9IuR5yGveV/B64wxcu6n3G89LeXQXRqtWJ9edH/vKe7YUfAaSXgUG9nVSNa9M6Mcf0RYL1tCefZstC0hvz3PRS8iPopeMDyAZhlr0Uwiql1qpK9p/NzkLWLPNPtU2e4e9Zv5gJzBdNQOu5EzeRI57QkxZUDOJe49v7ORY9uO7LoThTyXoY0hhzU/QKOjs0uWO4Tot2+rpqr6OBqDs2dz4+yTzCD0hRNHCH+RcElaxpxcQ33/E7Wq6+OoL86ezY2zTzqzacx/wdGUnIBikzehGOvvKOeFwCj6os/NVPl/h9SzPo7qcfZsbpx97BlG/NbsIxL/kw270KcZjkvOXphB6DtnVVHv+jiqxdmzuXH2sefMRivgcDgcDofD4XA4HA6Hw+FwOBwOh8PhODL5P/Qh3MlmUxVaAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} y^{2} \\left(x^{3} y^{3} z^{3} + 14 x^{2} y^{2} z^{2} + 52 x y z + 48\\right) e^{x y z}$$"
      ],
      "text/plain": [
       " 3  2 ⎛ 3  3  3       2  2  2                ⎞  x⋅y⋅z\n",
       "x ⋅y ⋅⎝x ⋅y ⋅z  + 14⋅x ⋅y ⋅z  + 52⋅x⋅y⋅z + 48⎠⋅ℯ     "
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff(expr,x,y,2,z,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ8AAAAaCAYAAABo6FFLAAAABHNCSVQICAgIfAhkiAAACqlJREFUeJztnXvQV0UZxz8vl5SgLOiCklKhmZpAXmIiwRcyTKnJQmxwKo7RdLMLCRaXIX/ZGGQZGCSSjb2W0SgkVlIJlBlRjjFqkqBZ9JYVoBQJJXHJ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U2e4e9Zv5gJzBdNQOu5EzeRI57QkxZUDOJe49v7ORY9uO7LoThTyXoY0hhzU/QKOjs0uWO4Tot2+rpqr6OBqDs2dz4+yTzCD0hRNHCH+RcElaxpxcQ33/E7Wq6+OoL86ezY2zTzqzacx/wdGUnIBikzehGOvvKOeFwCj6os/NVPl/h9SzPo7qcfZsbpx97BlG/NbsIxL/kw270KcZjkvOXphB6DtnVVHv+jiqxdmzuXH2sefMRivgcDgcDofD4XA4HA6Hw+FwOBwOh8PhODL5P/Qh3MlmUxVaAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} y^{2} \\left(x^{3} y^{3} z^{3} + 14 x^{2} y^{2} z^{2} + 52 x y z + 48\\right) e^{x y z}$$"
      ],
      "text/plain": [
       " 3  2 ⎛ 3  3  3       2  2  2                ⎞  x⋅y⋅z\n",
       "x ⋅y ⋅⎝x ⋅y ⋅z  + 14⋅x ⋅y ⋅z  + 52⋅x⋅y⋅z + 48⎠⋅ℯ     "
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.diff(x,y,2,z,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGcAAAApCAYAAAAoEzflAAAABHNCSVQICAgIfAhkiAAABBBJREFUeJzt2lvIFHUYx/HP+2qoVFRaVlR6UXTQrChFEJO3AxIRdLC8iZCSvIko1AtTKu+6rMiIiC7sJqgu7KITGR0oCSpIg6wsOlmaSCfSjmQXz0jz7ju7Ozs7u/Pu63xhmJ15Zp797cw8/8P8lmqZhw9Ty++4rlJFNZkcg/04umoh44XhqgWkuBZbcaBqITVjeR7XVy3iSGZKk/3HYR+m9lHLuKefzdrH+AO7cUND7Dq8nMRrKmAWpuEuMSo7PRV7EVdXIapmLJ9hVfJ5OvbiqOrkdMxN+BOzU/sexi6clGzvxuqG8y5KzpuDdTiUsd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rGCzzrAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{\\partial^{7}}{\\partial z^{4}\\partial y^{2}\\partial x} e^{x y z}$$"
      ],
      "text/plain": [
       "     7            \n",
       "    ∂     ⎛ x⋅y⋅z⎞\n",
       "──────────⎝ℯ     ⎠\n",
       "  4   2           \n",
       "∂z  ∂y  ∂x        "
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deriv=Derivative(expr,x,y,2,z,4)\n",
    "deriv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ8AAAAaCAYAAABo6FFLAAAABHNCSVQICAgIfAhkiAAACqlJREFUeJztnXvQV0UZxz8vl5SgLOiCklKhmZpAXmIiwRcyTKnJQmxwKo7RdLMLCRaXIX/ZGGQZGCSSjb2W0SgkVlIJlBlRjjFqkqBZ9JYVoBQJJXHJtz++e3wP5z2XPbffBfYzc4b3d3b3Oc/us+c8u8/uOYDD4XA4HC3G5cDDwG5z/BqYWILc2cBvjMyngB8Cr0sp0x84vuB1q6pPFXKr0vVwIU8fapTcqnR1HBm8ttEKNIJ3ABcCJwGvAa4BDgDDC8q9G7gM3YCnA6uA7cDAmPy9zLX7FrxuVfWpQm5Vuh4uZO1DjZRbla6OI4PhwNRGK9EM/BP4UMkyBwD/A94ekz4bGF3yNX2qqE9VcqvS9XAgrQ81k9yqdHUcvnweGFmivMnAPmBo4Nz1wOPAS4G/AleEyow0ZU4FZgFdEcdVJer4HL2BKcB+NHork2OR4m+KSBsErC35elBdfaqQW2Xb23AxsBhYj0JHXcCtGWW8l+4O+oFStRNJfajZ5Falqw2dRD80utBsLMwgZK9VwB+AvcDTwC+BaSgq4ejGtp9PBNagh/xeYCuwAnhjTP5jgbvKU5M2YCNwk/k9E9gBDDO/VwDfDZW5B1hi/n4BMDhwLAK2ASeWqCOnA/8GDgK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3unMOmvJuRZ9qAE1Zu4hfqMrCMiNrD5pql/HRxAlogS2KVqvPMSi8cBB4X0FZWfGon/NJokZ0LLxqW0K59mykLSG/PU8jut5D0WJ3F9qRFmaeSdsYUz5MHnva2Keqdvco15nXiF/zucSkbQeGhNIuQE51L9FfEhiNvngSXk75LT3XzIKcQwO+puErOQJNU58G3oKmwaCFqI0o3jkGed28bEC7KgageG1aLNiG9ajRXgX8KXC+FeuzHHWe+9EiYy0iz3y0ztVsXGQO0JZK0O6eDvP3TqI/zWJDPWwJ5dqzVW05Gb07dw+6n/ag9zQmovDNj1BYKMhUund0rUebDcJ00t0X8trTxj6t2u5BVqKw4nloNuh/4fwU9C5NG7LRPyLK+psSDobOX4l2HX7PyH4Yrd0MAc5E62MnlFwPK05EldtF9IuR5yGveV/B64wxcu6n3G89LeXQXRqtWJ9edH/vKe7YUfAaSXgUG9nVSNa9M6Mcf0RYL1tCefZstC0hvz3PRS8iPopeMDyAZhlr0Uwiql1qpK9p/NzkLWLPNPtU2e4e9Zv5gJzBdNQOu5EzeRI57QkxZUDOJe49v7ORY9uO7LoThTyXoY0hhzU/QKOjs0uWO4Tot2+rpqr6OBqDs2dz4+yTzCD0hRNHCH+RcElaxpxcQ33/E7Wq6+OoL86ezY2zTzqzacx/wdGUnIBikzehGOvvKOeFwCj6os/NVPl/h9SzPo7qcfZsbpx97BlG/NbsIxL/kw270KcZjkvOXphB6DtnVVHv+jiqxdmzuXH2sefMRivgcDgcDofD4XA4HA6Hw+FwOBwOh8PhODL5P/Qh3MlmUxVaAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x^{3} y^{2} \\left(x^{3} y^{3} z^{3} + 14 x^{2} y^{2} z^{2} + 52 x y z + 48\\right) e^{x y z}$$"
      ],
      "text/plain": [
       " 3  2 ⎛ 3  3  3       2  2  2                ⎞  x⋅y⋅z\n",
       "x ⋅y ⋅⎝x ⋅y ⋅z  + 14⋅x ⋅y ⋅z  + 52⋅x⋅y⋅z + 48⎠⋅ℯ     "
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deriv.doit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEEAAAAiCAYAAAAAl7SxAAAABHNCSVQICAgIfAhkiAAAAzJJREFUaIHt2EmIHFUcx/HPTCLRQ4i4oKAkB8UlGRfUEIxR3Bg8CGKCuXgIJhhPEknmEDOMiggeTUxCEL14EtRDLiKiIIJGCR7cSNQoLnEnrqiJC46H/2umrFR3VVfX9IzNfKFo3vr/v6r/+7/XP+rxPB7E6/gCl9WcZ1YwXHPcCL7EldiOWxvzaAao8hIW5MqLMInHUvkvfN+kU/2m7CUcwDER8qtT3Qj2Z/pchPead232sBgnYROO4mzchYlMn/04o/+uzQwfYiMexS2pbhifTrPd2/AHlmTqduAQThdRujk35tI0ZmkqbxVbOP/cX2Z8Bd7CJ7gT+3BvvXX0xBDexOOpPIZvcU4qP4OncmNexq5MeSHOzDzb8TXO7WR4nlj8FpycDP2K9fXW0TOjIgFvxS+4ItO2GR9lymvwA05tM9c2fIXzy4xeIxLi/FReJsJneReON80+/I2bcvUrhW+niJPsY9zTZo5xcbSfV8XgWnEytNiCz9S/V/TK9fgN/zj+YrZA7P9RESnv44SCOSZwWMkWyHIhfhQhdYEIr9u7dLyMNeLmeQR/ikS3TWzFLJfgJ6zD3jQmzxvYKbbKzQXt9+FzU3mkMmPi6x/Chm4Hd2CeSGSTae49IlF9kOqezPRdIsJ3PJUvFtFwdW7OR1L9CwX2xsWLXum/yfHE3pdSn11isQ+byjlECL+W2paKPX7Q1M20xdN4NVe3TuSLZbn6Ifys+Hi8rsd11GaF+GJ727RvFA7e0eW8L2J3Xafml3dplLvF1/kdDxS0j6TfoQpzDYvL0oY0bm0D/vWF7xSHZv65scJc14qoOij2e89UcayXh0hEk3ilCYebpLUdqoRfr7RsnNYHWzNGFbXpbRENqwvaYJXj7wnTTpMRcBgPiSNtTIgvE7k+o3hOROBLeEckuLNwuTgmFzfoU23ySlIVFokbWYtN2t/fl+NZfCP+FB3Bu+Ll3VDDduMcEOGaVZKqcJVYWIsnVMvws5IiJYlyYWNg1aaWkkS5sNFvtWnaKFOSOgkbA0FVJamdsDEQVFGSOgkbA0GZklRF2Pjf00lJqipsDARFSlI3wsYcc8wxx0DwLw875uAosZgrAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{\\partial^{n}}{\\partial x^{n}} e^{x y z}$$"
      ],
      "text/plain": [
       "  n        \n",
       " ∂ ⎛ x⋅y⋅z⎞\n",
       "───⎝ℯ     ⎠\n",
       "  n        \n",
       "∂x         "
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.diff((x,n))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.2 积分\n",
    "计算表达式积分，使用integrate函数。有两种形式的积分，分别是定积分和不定积分。不定积分和导数互为逆运算，使用方法与diff函数一样，只需要传入表达式和自变量即可。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADkAAAAVCAYAAAD8dkbIAAAABHNCSVQICAgIfAhkiAAAAt5JREFUWIXt1kuIVmUYB/DfeB8tLLRAUTuQSW2ScJAWtRDEQkKiVq0KBRFLFy2CBHEXEd7AhdAFLIgUJhQCkYGwIsS8VCDqSvGGk03pbHRKpz4Xz/vh8XznzCnnoAj+N+e8z+X/Ps/7PO+FByhFhhZ2NMj5BX7HlFFwLBBxrWgioEyzSfbgX7zbANdu9OOh0RKNx9OYMVqihD4MorsBroWiAOsa4GoM80QVP26Q8yTOYmxbMKZgsAzfipL/jYv4HqtzNpnOds3LMuzEH/gLR/BKRUDL0YVdFfq+xPtaQd6V5mrhw4JuJ+ZgcRnhyuTUL1b2A3yKQzhckVBRtl8cIAexBZ+LRP/BopI5j2BY9YEzP/mekKsMNqX5yjpgcdJtLCM8Kqr3eIlueu4/U51kCxsKvi8l+d6CfIpI8FhZMDnsSP5vpfG6NN6lsxNhatIfKiM7iqt4tGbSTHWSZ9y+4m2cFe2bx7zk01cz3ywMJe53ks8+TBjBZwi/tQf5lfgSk3FctNqreKwmgCJ+Fe1VxHmdizctfa/UcF7AVjyBbTgg9uj1EXwuy3VfPsnNeBPnsFbcOZfEPuupCaSNwQr5sM7WGkrfSf+BdyD3vwLXauy7c/yVeARL8YmozJ9u7dXMyKdrGb5L+jxmJtmPNbG8Ia6Z/mS/vcZ+TLI/VWN3Gz5L5K+ncaaZJLvESTzQYX0LS0VbHhNb5yRuiMdIFZ5Jc33dFuRb6GWMK3FqV7CuRf4vWvhB7J25JfoX0Cv25BKxGOtTjMW7MY/n03d/mXJQnEi94o7ZJI7hlrjPxie7TDOVJFqxhbcL8vkpnn48WdAdTj4vVsz1lTgDZpcpV4nD5rSo2mX8gvfwcM4u01ySE8TC/pSTzU2yK3i2xKd92R8s0U0VB86eijjuGd4XQT/XANcaI1f5nmGSeCx8M0qebvHW7i0qyl4ndxvD+BkTxd6/cYc8T4ln6Ueq7+sHuK9xEyfxyH1exnKjAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\sin{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "sin(x)"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(cos(x),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(exp(-x),(x,0,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAMFJREFUKJHV0D1qQkEUxfFfRAgEm1iHdEIgFuo2rKxcgFV6cQXZQzaRJrWtC/CDNHbp04iQJsSXIvNgvPGJhY0Hhgv/OefeO8OZ1Edx4ulAPQtv8IInvOM1u3vAEDNMsTw0fZA6Pwc+SXyUw1owdVKdB96r4Ht6SxNaga/xjetj4Q9scZWxBnZYRXO+9i3u/X1GkfFuavZv5TxcvncRPJXvPRSOpnaqR9eumtxM9RF3sUGpOX5wE/gQn/jCuCp8QfoFaukqtXE/L4oAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\pi$$"
      ],
      "text/plain": [
       "π"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(exp(-x**2-y**2),(x,-oo,+oo),(y,-oo,+oo))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果integrate无法计算积分，那么返回积分形式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEMAAAAgCAYAAABJqsWHAAAABHNCSVQICAgIfAhkiAAAAwxJREFUaIHtmV2ITGEYx3/D0pItKVvysVkuXO34qL3YfJRECYXdCy5QbmkviIyUi9WKXHBBKG3YC0QbWVqlfJWsr6idC5HFNliy2Hazu4yL5zmds7Nz5pw5c44zmvnX9J73fb7+857nPO/7ngNFeEIEGB02ibBRCjQC34Be4BAFPCnngGTKLxYqo5BQDvxBJmA7UKfX78MkFRRKHORzkVoB0Ax8B1qBbmA80BcctfzDRiQT+sMm8i8wykFepu0Pn+PWAb+ACsvYUeAVMNnnWL5hB5IZr332GwEeA6e1vxP4BMzKwecMhOsVrw6caoaRGT+9BrCBsSJdRyY6Biwlt0mfr+1Trw6cJmOCtr1eA2RAG9AONACrkEzJBcZkPPHqwG3N8DszQDIhqhw+++BvgbaeM8MJzUhKX3LQa1O9dSnjEaBJZQct41GgB9gMtAA3XPIpAeqBF8gK1wns0jgJ4EOOvDLiqhqccdCLAr+BDoZv1Y+o/SnLWAXQBezVfhWysVvkEGMs5p97BhxWXv1IIU4qX6+8HHFbjY650G1S3S3aj2n/AubjOAmIAydTbC8C9x38G394H+ZGEGAx5jFhv0dertCuhgdc6E5D7tJbYJva3UTuaK6oVn93bOQdKl8dJK+4Gu9xqd+IeZceIFt2P2AcFpfYyO+pfGouvPxeTbot11vx7+yyHPgK3LWRVyKbtq4gefUw/HnLhA1IIUyozQkvAdOgVP3ZLZk1Km8NmteQOljvoLcSGABeImeLODAIzPEa2IIxyiN12TRwSzk2BMlrHOZztiKD3kIk7d4AU3SsVu1asg1qA6N2pRbI3RaOa4PkVW4JVGOjY2yeEow8ZBkrkdP+wQ02qa8B4Czy6vERskq8U5n1BOw7r0rMyahKI58NfETejaaTL1Pbh9kEzYB65C4PIsXyMnIe6QS+BM0rijkZM7Mk/l8i09JaZrkO4qCWd7BORjWyPB3X/nRth5CUKygYNaIPmIe8eEkiBacgcY2R30hqQ2UUIiYC55FPAs+BNeHSKaKIIvIMfwE4Au4+qICGawAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\int x^{x}\\, dx$$"
      ],
      "text/plain": [
       "⌠      \n",
       "⎮  x   \n",
       "⎮ x  dx\n",
       "⌡      "
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(x**x,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHEAAAAgCAYAAAAlrJeCAAAABHNCSVQICAgIfAhkiAAABXVJREFUaIHtmmtsFFUUx39tobY80sYH1vdaayNGbURDYuURlWBioomKRIwhIol+ECR+UFOM0Q9IK49EiY/4IvWRIAkogeADE6OgiVKrjdUifqgtUqutilSgSKn1wzmTGWfvnd2ZXXbWOP9kM7vnnHvPf+65jzNnFhL8r1AClMVNIkE0VADNwAHgELCKJJj/ObwOjPk+y2NllCAUpgB/I4FbCtym33+Mk1SCcJiLu/pORrbR7UArMCE+WrGgCWgDhoBBYBtwSayMssQdSACH4yZSBHgfWIQE7lLgbeBnZHIXNe5FgvhL3ESKEJOAUeDGuImUZtBP0uuhAJsUEujWPPDJBa8BA8DEiO2vQO5jcZb2k5Hx+z2iPwfnqt+3onaQKYiT9fpnVAcFwpXAnUALcDhiH+3AFmAF7uQNwlNAB/BZRH8Opun1y6gd5GMlFgNWIgnH8zn20wzUAPdnsFsNzEKy9dEcfTpBbM+xHyteQJb6uwE2KeLdTuuRx6AX89TfHqAXe0FjLZIjXJwnf9uR8Ts9ageFWInzgZ3AQSTL7UTS9ZMMtiXAMqALOAr0Ac8AVUCPfvy4W9tttPjfgQzSLQZfrapr8cjfRM6pOYa+1iHb9jXKMVuMQ+7ra2QMeoGHlMM05D69yWNYzoHYqg3WB9iksK/ElaobRLa61cA3KvsIGO+zf051fciArQG+B3arrMfg4wvgOPaEpgHZ8rr49+paq778K3iOytcYuA0B1yJbrvPJdH6W4wblK2QM1iPBfEnlW3PkHIgPtdG6AJsU5iBepfJ9yM06GIc8KPvLdzNVtheo9sjLkZU8RnoQJyIB7MxwH63a/i79vVx/byR9N6pS3W6f3F96dD6PZ/DtBOpRZCU5mJWhjzCcA9GmDZ8IsElhDqJD/h5Dm3pkpnV7ZC+r/UKD/dWYg1iv8h0B/ADORmZ+D7BE27yHTBAThpEH+VwxXX19bNF3qd70rBmWsxV7tHFTgE0KcxDbVV5nader+mqffa3BtgwYIT2Izmq3nYdeNOPO/E8JLhv2ISs8VzgvD2Zb9LtUf5ZFnxXnE/mcWKXXfou+32fnXE3VoVHgN4PcKQdWZMFn0PN9MXAkwLaS/JQa5yK8d1r0tcj99ln0WXE+kdnpQb3WWPRn+OyG9GpKtcuAUwzyAb2adF4sQBIVZ4tcFmBbiuwOAwE22aACeQu0D1lJfjQCZ2J/yA/DORDHlcCtATYpzNupc8aZylh1pJ+JrxD+TCxBBnvQ38CDG4BjSPJzGnJEjAAXWeynqq/NAX1mg/HI+O236D9QPysMurCcrajE3Y+vD7BLYQ5io8p/UCIOypDy1hjwiEc+Gzc7rfLIy5HEwBREgE3Yz94ZyBbUjbvy56n9Fsv9LFL9Eos+DJycwp+4PIw7tjf7dFE4WzHF46gxwC6F/TnxSdy3IM8if+3oVNku0jMtp0K0H3ga2U724j4ndpOOBdrmPp+8AfgDOXsv8OmcrHumob8NyAo6x6ALi4Xq5xhSoF+F3Msw7jZ7Xh44W1GLG8TLAuxSBJfdbgc+QZKjo8C3yAo0JSOlwAPAd8BfwE9I8Ku0fYehTTlybnzukdWp7ICFu/NA7y9eVyEDHHrGB2AZMvlGkMm8GanS9AK/5oFzIBpwg3h+SOL5xoXKY4NF36T6y3P0s5QIs72YMQM3iKcWyGcN6RnzBNwi8XxLuwpkZm/LwXclsvI35dBH7JgOvIPUCME9a0Yo3F8UW5BgvKrfW5E/ZY0ptxJrSyljPUb0l8JTkfJXKmL7ooBzBh5BtiVn9rcVkMN1yGuvfuRMPIwUjR8kvViewAKnMO39zIuVUYLQqAbeQKooHcBN8dJJkCBBggQJCoZ/ADtzpuk1ETrlAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\int \\log{\\left (x \\right )}^{2}\\, dx$$"
      ],
      "text/plain": [
       "⌠           \n",
       "⎮    2      \n",
       "⎮ log (x) dx\n",
       "⌡           "
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=Integral(log(x)**2,x)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAO8AAAAaCAYAAABfLwsTAAAABHNCSVQICAgIfAhkiAAABbBJREFUeJztm22IVUUYx3/70uZqsNGLWFQcypaMyqIIyixxhSCIoCLyix0zItBeQUQj2k9ptVJJau+sUdjChoFktR/CyqDUMtjSirTVWne3pVepzXy5fXjmtOeeM3Pvedtz7rbzg8vefeaZZ2bu/87MmeecCxaLxfI/ZTmwA/gDGAY2AxcV2iOLxRKJ94CFyIS9GNgEDAKnFNkpiyUNDlACOgvsw6vAT8CUFDEuR8axKKL/ScAx4MYUbdYqDhNT0wmHQ7FCXwEcBx7KINYmYACZmNU4Axn3rAzajcOpwF1IX78DRoDfgW3Il7Q+gzYcJqamWZOHVqlwKFboHuA3oDmDWFciY1kRwbcL2AU0ZNBuHO5B+ngQeB1YCbyCfAYloBuoS9mGw8TUNGvy0CoVDsUJ3Yqs0C9kGHMPsJ/Kk/JJZDWfnmG7UZmLXKoHV+1pwAFEi1tStuEw8TQ14SKfxZwEdfPQKhS8RwW+OWCvQwQtAasixL0N+BC5VBgBepGs7YkG/zrgfmA38DfQDzwLtAB96uXnTlWnyxAvyTjeAM4B5hlirgYWAG3IpVDevI9kuo8H7IPAc+r9HE29IjSNqycUo+lYUYhWM5FkzG7KV6vVqqJ/VXTQr9KPKfswsB7Zrb5Utq3ACZp216nyfmAN0AF8C2xXtr6A/07gKOakRpxxeMxTZR2asjXAEHChob2iWYr0/SlNWRGaxtUT8te0Gi7Jd95KZKWVlk7l6Kr/V6j/uyjfqR3CQl+lbAeQSwSPRmQl0p1BZiv7N8DJPnsTstKXKBd7CiJyb0bj8GhR5dsD9nXIPd65akze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ae8gB/bDwJ9Ien0p+h8yWGobq6fFYrFYLBaLxWKxWCyWxPwLIwoRHjJJxHcAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x \\log{\\left (x \\right )}^{2} - 2 x \\log{\\left (x \\right )} + 2 x$$"
      ],
      "text/plain": [
       "     2                      \n",
       "x⋅log (x) - 2⋅x⋅log(x) + 2⋅x"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.doit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.3 极限\n",
    "SymPy使用limit函数计算符号表达式的极限。求极限表达式为：$\\lim_{x \\to x_0} f{\\left (x \\right )}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAM5JREFUOI3N0rEyQ0EUxvEfJcMVWhoZ8Qpq75PnoDJ0Kl5BK0U67yAUiUYmpZGYoRDNuePOkXszYxS+5ps95/x3Z3c//lC7uMIz3jHCOVpNUBsTzHGDU/RjfY+dOvA2hrqpfhb1y0XQfjSHWE29DUwxw7o0cBzew2cCX3GHNRxl8DD8oeYaj+GdDBbhLzVgWd/K4DKthM8zWO5YWKzN6lwVHIR3asCD8B9v0Lb8O97Ed2T9KgDlqdXInfiO3EBD5GAP1xjjA0+4wHYT9I/1BRgnMa7SDNsAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 168,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(sin(x),x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADsAAAAWCAYAAAB+F+RbAAAABHNCSVQICAgIfAhkiAAAAkdJREFUWIXt102IjVEYB/DfmCE0q4mi1CzMYshHiSxQGpOkbMZHWTEbKzayGGMzO0qTz0zYjJVGypSFr5VCapQ0MWkiicZXSCEGY3HOzfXOve7rfozS/ddZnOd9zvP/n/d9nnOelypSYy8G8AGvcREL/qmiCuIK2oUNLsQFvEDDvxQ1UajHd2yYYN7N+ILGLNsRDGNmpUhnYwwrKkWQBzW4g9NxvgcvMbeSpH24i9pKkuTBWoyiQzhDllaS7CBG0FSGWF1ChvxprM6x7ha+YV0akqsxUFvCXoPe+OxAjnXdQtrMLxB/Iy7hDb4KNdVpfCbMQHOBMT2xpgUf8QNLCugAi4UD5kFCQLew0VM51hxVeKO1OBtjDKMHh/Ew2s6kEVdA93tsQ7/wQlOhNwrYHuedcd6HSQnfE0J9tGBW1qhP+B2PMfajLss+GTfjs0JZkQ+NeI59cb5I+Lqr0iyeg894gp1RyGVMyeGbr566snyWR/L+PHw74pr2NOISaMAQTibs53Aj6VyXNOCZkGIdOCYUfZtQY0nUpBC0K/p98vtLyCDTcaWJlcRbzMth3/I3QXb79ZWaixCRjVcKn6xjaC2RpyhsFdJuJIroKSHW1Bjjehl0lR3rhXQdFNqsIeGiLvbrThM2e78s6sqIlUJdPRbaPtgkiM13uKTBPbnv7mzeCe24MvfUiPH95IAgNtVRngOZNm4M14Q7+5BwYj7C0yLjFoUm4bfsnXBHJdEqCL1dAscynI88o0IHNShcGWtKiFtFFVX8x/gJPTWWsk11Nc4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$x^{2} e^{- x}$$"
      ],
      "text/plain": [
       " 2  -x\n",
       "x ⋅ℯ  "
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=x**2/exp(x)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACsAAAASCAYAAADCKCelAAAABHNCSVQICAgIfAhkiAAAAY1JREFUSInt1c9LVFEYxvFPYmMrwWgXiJa4dG8EtWsVSIQgSPkPBG5auDJwIbiuiFZtgoJs6UKojVoUuG/RjwlapqFC6vjjtrinaO6cmbkz3gKpBw6Xc857nu973nvOvRxjJaF9xqk6MeUQ0/m3WR11gnoxecRk8qptVoJ1rGEDZyIxZcVVtiVWrLLfMYNuTOcET2AeH7GNTaxgvMm6dli/lOALTuI9KhjMxJTVVnYbq3iEWTwMPklIpkhWjQFcD/3nOQzOR7xKeIE9nC2QFTWAV2HsYl6DjK6F2Bt/gpU1GA5jb3CigUEv7uGd9BwmmTZVBKtZdV7jmfQ1jeJpJOYc3qIHS1iU3u4D9OEmuppw8rKqlN0t6XmsSG96SW1l74b+RMRvLMzdKYJV76fwuz7gPvpxKzI/EJ7zkblLOfxbYVUptls4jW/Sj/hX1ZV9EPpXM2uuYF9rlW3GymUAt1Vfmp8GQ9jFDh5jDgs4xJM2km3Eym3QhU91DC7gpbQiW1jGCC63mWwj1n/92/oBcrWuMROReQsAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\mathrm{NaN}$$"
      ],
      "text/plain": [
       "nan"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.subs(x,oo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAM5JREFUOI3N0rEyQ0EUxvEfJcMVWhoZ8Qpq75PnoDJ0Kl5BK0U67yAUiUYmpZGYoRDNuePOkXszYxS+5ps95/x3Z3c//lC7uMIz3jHCOVpNUBsTzHGDU/RjfY+dOvA2hrqpfhb1y0XQfjSHWE29DUwxw7o0cBzew2cCX3GHNRxl8DD8oeYaj+GdDBbhLzVgWd/K4DKthM8zWO5YWKzN6lwVHIR3asCD8B9v0Lb8O97Ed2T9KgDlqdXInfiO3EBD5GAP1xjjA0+4wHYT9I/1BRgnMa7SDNsAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 171,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.limit(x,oo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL8AAAAjCAYAAADFTts+AAAABHNCSVQICAgIfAhkiAAABwVJREFUeJztnHuIVUUcxz+65iOLNSu1KL2iaVoolUWF2u2BqVBY+MggKnwQmz2pKKP0n+xpmSKWBW1RhLqiIKUsPbRCfC0KZpbmq9KttNUyXdey7Y/vHPbsued1z717792aD1zO3vnNmfPdcc7Mb36/WcFisfiSAhqByogyi6XV0bbYAiyWYtEuwT37gQHA73nWYrEUlCQz/1/At0BtnrVky3vAr0DnhPZSIVedVyA3dFLeFLU8hdSc+Fkp4vv87vI+QBXwG3AUqAYuNfXOBRail+cEsBG4PktdQ4B/gEcT2kuFfOlchvrzjJwVJWcsMA/4EvgDjYX3Q+rH1dwdOAXMzUFbov5Jkf3gXw0cQp0wG1iK/oEPARcBu4DNwBw0651EL0HPLHRVA0eATgntpUK+dF6F+n56zoqSs8VoOApsJ3rwx9U81dTLdoJM8qxmpMh+8DcCT3tsz5jyOuANmrtbdxnbazE19UMv08KE9lIh3zq3A/uAsjy1ly3Xo8mtDZAmevBDPM0r0cSZ6++Vdf+kyH7w7/F5QE9jOwac6bGVoX3E5zE1vWDaujGhHTQTLEKb9wa0JFYD433qjge+QBv8emAr8BTQwafurcCnpr0G4ACwBqjIUme1sd3uKW+D+r3R3O9mhim/2ae9QpMm3uCP0lyO+vEdT3lB+idF9oN/mU877Yxtc8BzfgJ2xtS0Cfib4A1ilH2KsTcAS4BZwNto2V7tqTvL6D4ILABeBr6myb07zVXXWZ5r0W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tfdPJGmiBz/oeEEjcFlCe6mQL50PED7rlSJBmp2seu8CPKukSBNv8HdE0ZYVCe2lQj50dkIrV1VeFBWGMM3bye+mtGj9U4E2jCdQ6DDozfsE/cLfo6Vti/mkQtoejg4rBZ3hibKXCrnqHIAmjFSe9BSCQmouSv9MQJGVKUbAXHROI+zcfpp4M7/FklfGoQhIL1fZ6+i0ZVCaHhQ79YuvrkdJHjc7gedD2kpjB7+lCLRBITlnwD6GQnxBGU6H69CM7j6X3h6FlcZ56s5H6f4g0tjBbykSI5Cr8iT6O8whMe+rQCcanRfASd8P99R7Fvgud5kWS8uwFs3aI11lQ4l3+u+Yqe8Mfu8GdwZKRVssRcebjr8BZdHaogSQQw3atAYxCmXwHjLfD6Esag9PvW7IlbJYSgondXw3yoTFOfMOOiN/nMz/F2U9mX9OtoPwDa/FUnB6oTPuzkGtQej4Z5yMWAeau0gOE9DRgclo1ZiDNsa9fOpaLEWhK8qqvekpX0z4efM4VKAzHQ3IdfJugC0Wi8VisVgsFovFYmkR/gVX93JJ8CNu0QAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\lim_{x \\to 0^+}\\left(\\frac{\\cos{\\left (x \\right )} - 1}{x}\\right)$$"
      ],
      "text/plain": [
       "     ⎛cos(x) - 1⎞\n",
       " lim ⎜──────────⎟\n",
       "x─→0⁺⎝    x     ⎠"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=Limit((cos(x)-1)/x,x,0)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAM5JREFUOI3N0rEyQ0EUxvEfJcMVWhoZ8Qpq75PnoDJ0Kl5BK0U67yAUiUYmpZGYoRDNuePOkXszYxS+5ps95/x3Z3c//lC7uMIz3jHCOVpNUBsTzHGDU/RjfY+dOvA2hrqpfhb1y0XQfjSHWE29DUwxw7o0cBzew2cCX3GHNRxl8DD8oeYaj+GdDBbhLzVgWd/K4DKthM8zWO5YWKzN6lwVHIR3asCD8B9v0Lb8O97Ed2T9KgDlqdXInfiO3EBD5GAP1xjjA0+4wHYT9I/1BRgnMa7SDNsAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.doit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEwAAAAjCAYAAAA+NeykAAAABHNCSVQICAgIfAhkiAAAA65JREFUaIHt2V2IVVUUwPHfOGU9FIFRVoRzw4qC0JeCArNrRVgRNaFMPYgPGsS8BFIQZeVDXw9CpgR9PGTUSxLVS0xZ9EEhDSboQ1RaGWXf9mUZY6bTwzoHz2zuvXPueG8z17l/OMzM2mvvs/aavddeax+6tJQKRrFxHNm0YcZkG9BpHDeBPt/iQvzRYls6gok47CA+bbUhncJEtmRF7RhWlM/FS/gFf2IzLsr0TsPT+B4j2IpFTbx/CTbgfezL3vlCyb6zcQjrm3jfGCaywsajgmF8IpxXQT/exWV4XUz0RczCLRjC+fi6xPirMR9/YQ8uaMK2G8UieaWJPk1RUf6UzOWjuDdpuy+T/4onjV3Zy7K2x0ratAjnoQdVza2wIexFb0n9pqlo3mG7axg0J2vbj5OTtl4RF9+ZgH1V5R12Cg7g2US+ORvj5kTeI+Y4ikdzYTvSiu0iThT5Lvu5U8S0IofwI85ugy1FrsdMvJzI78JhPGjsP3otluMZ3J0L2+GwWunGvw3a8vbj22BLkX6xwt9M5DvwvEiVlmWye7AKm3B7UbkdQX8qciIWixg2UqN9NQawBifhIbwhHHi4qDhdMv1rhCPqnY57sA59ImXZImLaP6nidHFYv5j8aw10fi78vgJ/11KaDg7rxQ14W/0YeqsI8j9kf99Rb7Dp4LCFOFX97XgdnsPHmCfKvpWaS4g7hqrx87ANInWZXaNtgdh6X+LMTLYkG/PVllk5ydwkEsqNoswaxRcF2dpE/xtRd6bMx++ipp2btG3Nxr28JRa3kao42huxxpESrNbzVUH3kky2KhnjXBGvfhPbMOXqrN+H5U2fHKrGd1gzPCwmfk6rBjzWg36/yOR3T7YhZRkUxo5gm/ox4S1Rg34utsr27Km038Spw4C4hbhN1GnrxR3WnAZ9qlq7JdvKUnH90VeQPY5d4pa0Hj1q5yzDotIvsguPNBirqoMc1oOPHJnkneLaJT1yU64QK+eqgmymuIFYmug+gfcajFXVQQ4jitSD4v5nHy4u2W9QXJ3kTjtLnE4LE7378dnRmzm12CJWx+KCbIHGuU/+7M/0c4elQf4BHf7FKb0Pu1JkwDPwU0G+TQTuelwrMuy8aN0rypEzEr3TxTY/JshLheWijhoq2e9SUY+tSOTD4nNakZ0aB/2OoU980c6/9swTN41laqkTjN2+OQPiDmqlWJ3rxOHQV0O3o5glviE+lcg34YOjHHtQ1HYHxLZOD4EuXbp06fI/8h/u7uQM2pcNJAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\lim_{x \\to 0^+} \\frac{1}{x}$$"
      ],
      "text/plain": [
       "     1\n",
       " lim ─\n",
       "x─→0⁺x"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=Limit(1/x,x,0)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABEAAAALCAYAAACZIGYHAAAABHNCSVQICAgIfAhkiAAAANNJREFUKJG10TFLglEUh/GfurU0SZvQGCI1OBcZ+BFc6hMI+jGaXFzEKQjaWtqiLRChpKU9hcBBMGgRRRBteN9BLu8LDXq289x7Hs79X/ZUN/jGAg84iPklPvCLZxTSBCX8oIYqhnhBEXN0cYF2LMwkSe7Q3OqLWGKCx+DuGypJkgFOA9bBCscBb6EB2eAgg03ARsghH/CNlOfco77VH2KMKV6DoXdcJUnO4oEaztFDXxT4XJRZGbf4TNsErkVfPMMTjmJewRfWouxO0gT/qTDH3dQfdTgpAZFH3n4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\infty$$"
      ],
      "text/plain": [
       "∞"
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.doit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEwAAAAhCAYAAABz/U2vAAAABHNCSVQICAgIfAhkiAAAA4lJREFUaIHt2VuIlVUUwPHfOGU9FIFRloRzwoqC0JeCArOxQqyImlCmHsQHDWJeAimQsvKh24OQKUGXh4x6SaJ6iSmDLhTSYEJCYSldKLvbPWOsdHpY34ffbM6ZOdeZOZ7zh49zztpr72996+y99lr7o0tTKWEM2yaRdQyzptuAduOEOvp8g4vwe5NtaQvqcdi/+KTZhrQL9SzJkvIxrChfgBfxM/7EDlyc6Z2Bp/AdRrELS2u4/wpsxbv4I7vn81X2nYsj2FLD/cZRzwybjBJGsFc4r4QBvI3L8Zp40BcwB7dgGBfgqyrG34BF+AsHcGENtt0oJsnLNfSpiZLqd8lcPoZ7krZ7M/kveML4mb0qa3u0SpuW4nz0oF9tM2wYB9FbpX7NlNTusC/KGDQ/azuEU5O2XhEX36rDvn7VO+w0HMYziXxHNsbNibxHPOMYHsmFrUgrPhRxosi32ec+EdOKHMEPOKcFthS5HrPxUiK/C0fxgPF/9CasxtNYnwtb4bBy6cZ/E7Tl7Se2wJYiA2KGv5HI9+A5kSqtymR3Yx224/aiciuC/kzkZCwXMWy0TPsGDGIjTsGDeF048GhRsVMy/WXCEZV2xwPYjD6RsuwUMe2fVLFTHDYgHv7VCXR+Knxfg7/LKXWCw3pxA95UOYbeKoL899nvOyoN1gkOW4LTVV6O1+FZfIyFouxbq7aEuG3oN3ketlWkLnPLtC0WS+9znJ3JVmRjvtI0K6eZm0RCuU2UWWP4rCDblOh/LerOlEX4TdS0C5K2Xdm4VzTF4mlmo2MlWLnry4LupZlsXTLGeSJe/SqWYco1Wb/3m2d2dQyJUmkUu039P/aQePBzp/i+dTEoasTbRBa9RZwwzC+j+1GFa16DNuwVpVpLWCmK076C7DHsF2dYlehRfkcZEXVYkf14uAEbZxQ9+MCxh7xTFMVpQEy5Usycqwuy2aI+XJnoPo53GrZ0BrFMLKP14pDvkir7DYnCNnfaPBE7liR69+HTxs2cWewUs2N5QbbYxDtTfh3K9HOHpUH+fm3+PiA9rbhK5Cez8GNBvlsE7kpcK/KfvKQ4KJLFsxK9M8UyPy7IE7nVIssdrrLfZSJbXpPIR8TLjiL7HCdBv0+8b8zP4heKc6Bq8qaTjF++OYPihGCtmJ2bxebQV0a3rZgj8pUnE/l2vNfg2EMi8z4slnW6CXTp0qVLlynkfyn93/LF5I9GAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\lim_{x \\to 0^-} \\frac{1}{x}$$"
      ],
      "text/plain": [
       "     1\n",
       " lim ─\n",
       "x─→0⁻x"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=Limit(1/x,x,0,'-')\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACIAAAALCAYAAAAa5F88AAAABHNCSVQICAgIfAhkiAAAAO5JREFUOI3d069Lw0EcxvHX1GQxDZtglCEalhUn+CesuL9A0D/DZLGIaTBYs9jEJoigYrFvuoGIoGCR6UDcwveEL4cTDYfgAxee53583tx9jn+sGrp4RROTIV/BFZ5xhJmUEPN4QhVraOMYJfSwj2XsBqhCKpA6tnK+hD4ecBCtPUdl1EEdDH4xmtH+SyxE2R7eMRvlO9j8NBPRZBtvoyi/0H3kCwEwrxuMo4jbXD6Q8Gka2Mj5KdzhESdR4QuspgJZDEWrWMIpzmRN3JP1UBnbuJbwRmBd9n1fcIjpkFfQwoesl+ZSQvxEY38N8K2Gk+85FrKxPB4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$-\\infty$$"
      ],
      "text/plain": [
       "-∞"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.doit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFcAAAAhCAYAAACsszewAAAABHNCSVQICAgIfAhkiAAABKdJREFUaIHt2nuIVHUUB/CPmqZZWFrSeweyzIgiivCPMiorrYiIRILERI3YXv9U9LY/jPwjy4qgB0EPogyjQjASwqKS1CQholKy7KFlptvDMtO2P87v0vXunZ2dnd11W/cLw90559wzZ86c33ndpR89ggpa8WwNWj86iIF724C+jP1q8L/HOPzSA7b0OdSK3L/xOTb1gC0dQUXXp6nnsRnDO3n/6cKmmUVGLedWlH+ZPP04LMLP+A1LcXKSOwxPiR9nB1bh3Hqt70acgasxD9s7qWM1XsdcHFhNqKLjBS2jv4MteA/z8Sr+SbTj8SU+xgIRITuFk4/t5BcZjBNxRCfvL2IpWjCsQT1nCn/cWU2gon7ntuKuAu+eRN+KJ+x5OqYl3sP1WN5NOEEEwlNdpO8zbMCgMmZF/c79qkTZsYm3HQcVeINEHl9WoF+Gt0X6+Asb8S6a67SxgpfFydmBj3CpcsxL951fhb808a8o0Aekz2pNOjLMSbSLMkKjrdga7C7QNqbrWpGD89iNH3F0jnYt3sBJWCzSyxJxVGfUYUsTVgoHv4CFIve/oTzPT0z2fFhF360isufaM4AexHQ8jdtz9A/S9YIyZRX1R26RniHLx2X4Or0yrBbROrpE9tA6bGwV0ZPHRYm+pEAfjl34pIqNGZ5N91+T3t+Z3i/UNjBHJN7KjFCrz+0p7BLpoogtdejYIKIsj7fwjSg4eRwlorFWi3k3puI+0Qncn3ROE1Gdxy8Kxbo3TGgv4gB8Kgrd5aKFqxdlKQq+xSEF2qh03VZD53ei02nCY1gucvDOKvJb5U5bb3DuQyKHfYOb8JrIy8tEH9pRtFSh79L2e/6ZrkM7oPen3N8z8Uc7ssNyunuFc4keeLyIqEvwDCaII1iWixvF5nQd1a4UV4kC9kN6f3M7sgNxcE53r3FuhhZRfGaLYjISZ3fD52wSETm2HZmL8ZxIV6eINcAsMcSUYaxo09Z0nZmNY5LywrpYVN/JOVpF/WvRdxK/iEWJPqaEd5Y4/uv9Nw1emeRfr/I5MxL/hir8vYIWcewWiSM4X7QzrWIIGJyTreg6516V6NcX6KcmmzaJvUkeq9I9ZafpJZHfj6lix17BdaKIrRfRslXsI27TdsKr6DrnDhE/6oocbUyibROpoIiJSVdx8BghClm1qO42NIsxeYcYGLojh3YWdwhnndagnhtVj+huw1QxHMwWS/dH8bvOb8W6GkPF8LG4AR3DxMi/qJbgFDGKNuVoj2Cd9hv7Acqr6Aoxg+exDg/UMqQHMUGMzZ1dlo8TE1ylluAAUUQyh9wiGvpiYi/iHBGR+Q3TEJHgpxRkHxcbr30SF4qjfDt+1fEpqVmsGTMHHyny0ISC3L34onEz/79YLqJuUo52lv+2T+29ssclmXOLSX6OaMj7PMqa9/NErzdQbpQTlX5cO7omiz41GxG3iEXK4QW50SLV7HPIGujpomd7s4P3jRc9avEJ6AptH6Os1bsKWo+gSfyfQvZM7BSxs+xI77a/PVNIhqliPTdLRP0CUfiaSmT7LEaKB2xPFuiv4P0GdTeLJw9/idRSLHD96Ec/+tGPfjSMfwEPFT1UCTZKiAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\lim_{x \\to 0} \\sin{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "lim sin(x)\n",
       "x─→0      "
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=Limit(sin(x),x,0,'+-')\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAABHNCSVQICAgIfAhkiAAAAM5JREFUOI3N0rEyQ0EUxvEfJcMVWhoZ8Qpq75PnoDJ0Kl5BK0U67yAUiUYmpZGYoRDNuePOkXszYxS+5ps95/x3Z3c//lC7uMIz3jHCOVpNUBsTzHGDU/RjfY+dOvA2hrqpfhb1y0XQfjSHWE29DUwxw7o0cBzew2cCX3GHNRxl8DD8oeYaj+GdDBbhLzVgWd/K4DKthM8zWO5YWKzN6lwVHIR3asCD8B9v0Lb8O97Ed2T9KgDlqdXInfiO3EBD5GAP1xjjA0+4wHYT9I/1BRgnMa7SDNsAAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$0$$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limit(sin(x),x,0,'+-')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```python\n",
    "limit(1/x,x,0,'-+')\n",
    ">>> error\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.4 级数展开\n",
    "SymPy可以计算表达式在某个点渐进级数展开式。比如说，计算$f(x)$在点$x=x_0$级数展开式，可以使用$f(x).series(x,x_0,n)$。其中$x_0和n$是可以省略，默认情况下，$x_0=0，n=6$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMIAAAAYCAYAAACoRCJ4AAAABHNCSVQICAgIfAhkiAAABZJJREFUeJztm2toHFUUx3+bSk2sGPFVFRWrNVoRo/jAN5tEENRatX5p+8HR2iK0ig9EWijmi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xIQ7kWiYBMyX3PiAmABsljKu57tj6B70vF7KfBbgzmZ8vHCLci8OyjCrwCeRObOPUjePgzissNx+vcQjg/JAxlgif5+1VE+pX/DTAHjtrONNgcPX2RpnqnRIiQDMKG6nmkwp7j5zEBSprsC5O7T9kaBE2psE8zscBrljExQdF6isgeonNPbo8qegPpx29lGi+odDyOcpTkc4XokUo4CxyPTgQKVOeN6ckqCjz2PXu4j87DK7KMclWuFhZkdvtJ6C3xkOpAd8AJyzsqJDHKsYtJdyYEk7GxjHsL/lTDCWRrvCFchQ+FnyNEEkGMgJeC1BnBKik8/kiqc7fF8DeWcfZyH9SzM7PCg1htHorsbNyIfeZFyxseNIdVRbXMxKTvbuEN1rfQSuBlZJA0gq3P7Ze2yUHlXFyzMjN2JbL9PAGe6no2ozqsN+JhySpLPl8j5rmq4nfJm0UYk2+S+LMN2Lcz6pgVZ/JaQ1PA25KzRFiQ7VELs5LcfskjlVrjKk7SzjZcRe57qJdCLfyYhb9CoRXRjz0VSWz8ieWg37A2R9wz4mHBKks8lWtfr4FkvwRmenEG7UPu0dSHwBhL9C8hewdvA/cBRAXVnIjZ931GWdL+D7CFMEc/IkiJGPIZ0btAO7XSEnVp1n0NKEvcQz6iSImaMES2NPJ3Qihx+21mn9tqQzcChOrWXIkVoXIMcgovjH3OCMA+Zap5eh7ZSpEiRIkWKFCn+r/gHv8EJn1Q2xysAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1 + x + \\frac{x^{2}}{2} + O\\left(x^{4}\\right)$$"
      ],
      "text/plain": [
       "         2        \n",
       "        x     ⎛ 4⎞\n",
       "1 + x + ── + O⎝x ⎠\n",
       "        2         "
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=exp(sin(x))\n",
    "expr.series(x,0,4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$O(x^4)$表示最后一个的意思，指的是所有x项的幂次大于或等于$x^4$被省略。可以在外部创建和操作这种表达式形式，表达式会自动省略高次幂。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIoAAAAYCAYAAAAlKWUsAAAABHNCSVQICAgIfAhkiAAABFJJREFUaIHtmluIVWUUx39nimlGo+khH4yKLuOokDOGEiUKmkGkhqC9DL58KtGD9pA+KYhPMZMYiBcCETxeMAS7QBAyiB1EUZvxjgbB1AjaVCPeEkc7J08Pax1mz2Zfv332ORPuP2xmn7XX+tZ/r732+tb37YEMGR5DrAIuAnf1OAksrCujsYf1QBnYXm8i9cRiYAEwCWgDPgOKQHs9SY0hvAX8BlzgMU8UL9wEPq43iQTYC/wFjE84TgvQD7wDFPBOlBlItVmZ0Nf/Ck8AncA/wLQ6c3kVqW7nkMR9CAwAeaAjwG4m8AhYUwUOB4HP9byAf0X5FhgEnq6CzzGNacA9oATcQqaieiEHbAAeIA/8R2Ab0A0cVlkRWOFj3wPcBpoT8vgIOAM06u8C/onyJlJV1if0GRtGHc+tkb9GoBV5G7uAG8DrFuMYkvHOAbt1jF6kZ3JjPpIoJeAN17U2JJF2WvqvYDIwBExxyAoE9yg/A1eRquyJHuTGlrjkOaRMlpG3IQ4M9gGvBp8jwC4L34ZkibJO7fuApgC9raq3xyXvVvl8H7uosTF6XnIcZSQJS8BTHmNvVJ33/Eh3AP8CVxidTV+ooU12V4jOtbCtBp+jwH4L3wZ73q8gvdGwngdhofr5xSXvQx6kXxMbNTbPIhXVefQCB/Q85zH2uzrG5iDieVUy+ruy7j4INAQZ+sCQ7M2Mw6cbmAO8jPQqXcib876FX4M97x1quyWCbrvq/umQjUeS5FKIbR67Z1UgeOpp0XF+CnL+AvImDACr1eAwI41QXBiSJUocPnlkbn2ILCmPEFA+Q2Cw450DflfbmRH056nuZYesTWU9Iba2z6pA+D7KMPBHiA5d6rQMnADGhRkoBhx2UY58xHFt+UTFQAjPOLyfV50i8GQE35VeZp9D9jYjlSEMacXmOlLVAP8bGXKcrwTuRxx8CzInOjEd2THdgzwQJ85HHNeWT1RUk/dz+vdvHIH2QQ5YpuffOOTD+jeoCa4grdg0O3h4ohOZ1weRLP0yoUNDsqmn2nyiwmDH+yVGVhVhb/cy1b3C6J6iUpWOh9inFZsGHbffT2EB0q1fAiYg6+kio9fgcWGwT5Q0+ESFwZ73NbVdHKDTBtxB7meW61oO6bGG3EYOpBmbqQj/r70uzkbK1q/ARJV9qAbfJXBqsAt4WnyiwmCfKGvVth+pDm4sQpKgxMiKxY1DOkarx7W0Y7Ncx1rtvtCBbBUPAq+5rvWq0RxLp4b4AU+TT1QY7BOlAWlOy8i/O+xDvvXsRFY3ZeTePggYo1P1VrnktYjNV0gSv+gUtiLLoFt4f46vbL6csnRqiBfwtPlEhSH5p4elwA9I9SgieyXHgE+BZ0JsG5E4nHbIahGbFqSJrUXVzlAlVJbO7u9AaeITalOxM1QRTcgG4vc18teMbBYecl/w/TqYYUygBJxFPtz1IdNXmpiE7GpvQvqgDBkyZMiQoV74D8z+eQcq3c/LAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$x + x^{3} + O\\left(x^{4}\\right)$$"
      ],
      "text/plain": [
       "     3    ⎛ 4⎞\n",
       "x + x  + O⎝x ⎠"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x+x**3+x**6+O(x**4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHQAAAAYCAYAAAArrNkGAAAABHNCSVQICAgIfAhkiAAAA0FJREFUaIHt2F/oX3Mcx/HHbGmtibCNcqMoCXPjQlmd30ZKYdiNXfDVtBRJskStfrkwxcJWyIV+ios1RY2GC9SQstrqV34XpF8u7Kct/6OIuXh/1u/rOOf3PX++5/drOc86dT7nvD/v96v353zen8/50NMzxGP4HD/jOA7giiVV1NOK93CPGMQr8SbmcO5SiuoZH6vxF25eaiH/V84Ys7+zks/vS96vEwO+J7XPw71iZn+F3/ETPsa2DvSdzmzBXhwSS9xJvNZ10H04guUl77cnIROpfV9qf4vXsQuv4Mf0/A0s61Dv6cRRkZNfMGMRBvRpHMMlC9gcxAnzA75RlOf8TLwA3wjRdzTUM0j9s4b9x81AOz0TuFR84JmSAc0n8v1keHvu+TJMpXdPFQTbjbuwSZTOIs4WA3hAlF34ILX/ztnO4aV0n5X465KmeeiSD/Flil2Z9SLZX/h32dydHL1c0GcPvsPlI3xvTT6qbph2JPtnK9rnGWg+I5rkoUs9eTI1Su5UMh6k9uOpvc9/Z/QLYoHeKMrkqWt1gd/9+BUrK2hYgekU98YqogsYaJfAKdXzsBh6hsnUGNCLxG5zFg+kju/izALbkyXXZM5upVjM91cU/Ezy805F+yIG2iWwTh4WQ88wmZqbol3mB+cTrGop4Jbka2sF2weT7YzqBxSzyj+uomuqot+meehKzykyJQO6oqTD8aH7bfitZsA8t+EPo2fc/XherF2blP/P5nkO5+SeXY1b8apI8DBHK/ptmoeu9DTiTrHrPCa+ghdb+lsuflUOjrB7KMWbxtqWMWlf4sadh7Z6hslULLk3iZk0jTWi7P2Jy1oEn0jBty9g82iyOYLzW8QaZqB5ArvIQxs9eTIVBvQ6UVK+xoXp2ZbU8a0WwfeKX4B1Je93phiHjfdQf6BZArvKQ1M9RWRGrKHr8bY4R71BlBni6O2wqP0bxDliXTbjU/GvmuduPCEG/JDYEOWZVX/T0JQu89CWzekifg3hWvO5OYFHiKO6OfyAqwocXS++hs8aiLgm9X245P2k0TvAjxrEpf6M6DIPTfTkmbRwnmYb+q3FkynYxYsRrKd7ZnS8Je/p6enp6enpGQf/AHi4IPXqfpHbAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{x^{2}}{2} + x + 1$$"
      ],
      "text/plain": [
       " 2        \n",
       "x         \n",
       "── + x + 1\n",
       "2         "
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr.series(x,0,4).removeO()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAv8AAAAZCAYAAACmeUGUAAAABHNCSVQICAgIfAhkiAAADm9JREFUeJztnXmQHUUdxz+7xJBwJQJyyRESiIZTJCAghCVBKEBEQUq5dDCAWpxexaHIlggJl0YuMVqwHIIYIliI0YAQDkskKGiQAJrkIUfEoAQiBMjC849fT+1kdqanp3vmzbx9/al6tftmeqZ/r7+/7ul7wOPxeDwej8fj8Xg8Q4KzgfnAa8Ay4E5gh0ot8hTFycBfEW1fA/4AHFKpRZ6iOQdoAldWbYinEnoR/aOff1VpkKc2TATWrNqIGrIpcD1S31kJLAD2rdSiatk76WB3q63wtJwe4GpgL2Ay0A/cA6xfoU2eYngeOAvYFXkQ3AvcAexUpVGewtgDOBFp4Hk6l6eRCk342bFaczw1YEvk2f5WxXbUjdHA74EupCNsO+AM4N9VGlUxK4CpVRtRNTcgTrB21YYUyK5Ib5CpuOsA7wCHlmZR6xmKukJ+bQH+C3yxHHNaTifrOgpYhDTY5+F7/jvVF3qBJ1pmjadd+CmwluZ8p+aXC5HKv2d1LgHGlRlBg8FDlHUZqpwIvAt8tWI78rAPMBtYirTwlwJzgYNj4W5X59YxuOemiB4f1YTZGGkgXK6+bwCcoOL5BzKU9irwEJIJqxxBGsq6grm2awBHAW+T3jMY19XWplbQ6breClyk/p9HduU/qm1R+fU4BsrvEwyvKYN29AUopvzuBd4AXgCWALcAYzLiTcrnnwauAB5Epgg2gZtSrnfxn82Ba4EXkd/cAGYA782wuVMZC1wAPIZ03IRp1gfsnHLNFOAyzT3bMb8UVXY+iaTNzUjj53HgFGQkYKiRJ80mIGVHaTSA5UiBFf98vcyIDZiL2DayYjtM+RZSQC8DrkNatDOR+fsXx8LursKeY3DfW5GCZg1NmJPU/fZT37+kvr+I9DhMQwr45er4bV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CM8zkG748b8nllSz+yv3NvwiewiDOgeF2hvtra6Apu2up0dbEpiwB7bb2uZqRpW2R+7aXayn+7+QLUr/wG+CTy8O9jYFeQRZFj0f3Sbf1nHLItZVgxmoa8d6SJbB+7QY7fEyUgv/+U6R829oR0I+trmsiWrTciOyHNRHb1aSI2697TMJv06VPtll+qKjtvUHEeqwnTqjQbRfpbeZOwTbMnMOscyM2+iCBPIQm2CmnB3g18DretlgLcKonDkS2hwjfjbaO+v4LspRsnfIHEw5bxFcH6SI/JEmTI6T/AL4E9EsKOQhpZti3R3ZDfm/bK+F51XveZZxFvQLG6Qv21zaMruGmbpautTSYE2Gvrdc1Gp20vxeXX8F5VVf7b0RegXuU3ZPtEI0dYnf9sgbxdeCnyu59FFgu7jD4F5POfsv0jrz1JHAH8GqkjrUIaTQ8g+7jrtnoEmWVxbcq5dswvrS47QaayvUb6m3WHWppNYvBObh1DuG3WLlUbUgKn4tYKDbdhy3rjYB0ZyrqCm7Ze1/rSyXk2L94X9HSSL3iEGQxMQ4nj84ue0cgUuU6qDF9DcdO1244RSC/EnVUbUjAjkS21bnO4x0LMt0yrG0NVV3DX1utaTzo9z+bF+4KeTvIFj7AW6WsofX7RcygyRX2TQiyqPwfgNko1JJiEvIXYZseBujIBGaYdU60ZlTIUdQWvrdfVE+J9weNZnfcDa6ac8/nFExJfr+DxeDwej8fj8Xg8Ho/H4/F4PB6Px+PxeDwej8fj8Xg8Ho/H4/F4PB6Pp8b8Hzw/JYrU094xAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$-5 + \\frac{\\left(x - 6\\right)^{2}}{2} + \\frac{\\left(x - 6\\right)^{3}}{6} + \\frac{\\left(x - 6\\right)^{4}}{24} + \\frac{\\left(x - 6\\right)^{5}}{120} + x + O\\left(\\left(x - 6\\right)^{6}; x\\rightarrow 6\\right)$$"
      ],
      "text/plain": [
       "            2          3          4          5                         \n",
       "     (x - 6)    (x - 6)    (x - 6)    (x - 6)         ⎛       6       ⎞\n",
       "-5 + ──────── + ──────── + ──────── + ──────── + x + O⎝(x - 6) ; x → 6⎠\n",
       "        2          6          24        120                            "
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exp(x-6).series(x,x0=6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 8 解方程\n",
    "## 8\n",
    "\n",
    "我们知道，在SymPy中符号方程等式，不能使用=或者==号，应该使用Eq函数。\n",
    "还有一种更简单的方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADMAAAATCAYAAAA9DTUcAAAABHNCSVQICAgIfAhkiAAAAbNJREFUSInt1jtoFFEUxvFf8FFooQiChpBGwVSmEi1MZ6WdaBELHyCCKCimEXsfAW0kCJpma22ClaRTUEQbwVcnCxYqClFExWcs7gkZ1t3Zu2aSRckfBuaec+4538ydM/fyHzOJaexusPegFr4LC6RlJOqNtPBvwlfcaZVgED/xDEsK9kuR+FolMvPYGjVvtPBP4gc2zxh6mgTVcACH4v4MzuI6hvGrRMBJrO5A8CNMtPAtwwe8Q3+Db2/ouYwTZQX68AV1HJfezi0szxBXj/jcq9Ym3+2I6y3YVuIl3mBVhibnCwXvYkXOpHngnD97eDRsB3OTnDL7MAMViuuUXaFhNMYD+IZ7mrTI0iYJhnERr7FO+iaPZhavsmdIoqexLcZj0o/pWNhL2Sk9+WOsxXN8l786ddX2DDzFJ+yLOVdyhGzHZ7zA+rDtiQRlb2++uRoaPuIt1rSbMIj3eIUNDb6HkWyoWo3Z7De7kofbBW+U+mNKYQMqsCMS3a9QYCcMRf0Hmu+L/xQ3pVPJlm4LmSszTT/WbSF/Sz9OY1w6SD7RvU17zhyRVmNKOn/1locvssiC8huuTniHA6cnLwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$x = y$$"
      ],
      "text/plain": [
       "x = y"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Eq(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAAWCAYAAABud6qHAAAABHNCSVQICAgIfAhkiAAAAihJREFUWIXt2EGIjVEUwPHfGJLSGLOhJFZq2EhSFuplNSUhbKxspUhZ2M2URCILOwtNsVLKlIWyoChSotDYqFHIgsXMLEYNxuLez8z75rl8z/vee8b719d9vXPPOfc777x7zr10KIVDeIxxfMPm1i6nKQxhGh9xCxuKGtiI75jEVZzG6sat7ycHcBkPMIEZXG+h7QrO4U6c/6So06NR8VhRxYI8j34mMaqxgftb20+F5FmeFyxKKPXFcbSAo3o4IfwdenCkzWy/RhdW5gWLE0rdcZyuw2ER7rWx7ezdu/OCVMZ1SJAKXG8cp5qxkDblSxxX5AW/ClwXdgib6duSFvUvMBbHSl6QD9wALgoleAuuCP1MyvBMgadR1bJZXBMS5wJu4AzWM784DOB4/PxS6IFSvDGbzn/ChwJz24H3OItLOBi/u2s2E6vowR5hb3unRkUpkYryMrMe27uizkNswpJMUGuPm8AIbmIN+utc6EJgZxyH8Mqc1ixVVbOi0JeY0yqGhUw4XLKfrPEdywtSDXAW3bJ7vb3xYfYsvF0IDnzCyZxOtqavJdiux08Vg8KvWimiVAdD0pV4rIbOM2FLmXcUaoDtuQzHeet+M6+KU1FpXxGlJtArXHGdb4KvESEGq4oo7Y9Kt7FW+xzPdgstUBlXXBlLsU24hxxX8N2X4YXq1P5fLjLnvvNgrUmp4jCFrUJJ7hfupFKniIXCfaEYfMYj4U6vQ4cW8wOo/5Y5FpjzqAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left\\{-1, 1\\right\\}$$"
      ],
      "text/plain": [
       "{-1, 1}"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(Eq(x**2,1),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAAWCAYAAABud6qHAAAABHNCSVQICAgIfAhkiAAAAihJREFUWIXt2EGIjVEUwPHfGJLSGLOhJFZq2EhSFuplNSUhbKxspUhZ2M2URCILOwtNsVLKlIWyoChSotDYqFHIgsXMLEYNxuLez8z75rl8z/vee8b719d9vXPPOfc777x7zr10KIVDeIxxfMPm1i6nKQxhGh9xCxuKGtiI75jEVZzG6sat7ycHcBkPMIEZXG+h7QrO4U6c/6So06NR8VhRxYI8j34mMaqxgftb20+F5FmeFyxKKPXFcbSAo3o4IfwdenCkzWy/RhdW5gWLE0rdcZyuw2ER7rWx7ezdu/OCVMZ1SJAKXG8cp5qxkDblSxxX5AW/ClwXdgib6duSFvUvMBbHSl6QD9wALgoleAuuCP1MyvBMgadR1bJZXBMS5wJu4AzWM784DOB4/PxS6IFSvDGbzn/ChwJz24H3OItLOBi/u2s2E6vowR5hb3unRkUpkYryMrMe27uizkNswpJMUGuPm8AIbmIN+utc6EJgZxyH8Mqc1ixVVbOi0JeY0yqGhUw4XLKfrPEdywtSDXAW3bJ7vb3xYfYsvF0IDnzCyZxOtqavJdiux08Vg8KvWimiVAdD0pV4rIbOM2FLmXcUaoDtuQzHeet+M6+KU1FpXxGlJtArXHGdb4KvESEGq4oo7Y9Kt7FW+xzPdgstUBlXXBlLsU24hxxX8N2X4YXq1P5fLjLnvvNgrUmp4jCFrUJJ7hfupFKniIXCfaEYfMYj4U6vQ4cW8wOo/5Y5FpjzqAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left\\{-1, 1\\right\\}$$"
      ],
      "text/plain": [
       "{-1, 1}"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(Eq(x**2-1,0),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAE4AAAAWCAYAAABud6qHAAAABHNCSVQICAgIfAhkiAAAAihJREFUWIXt2EGIjVEUwPHfGJLSGLOhJFZq2EhSFuplNSUhbKxspUhZ2M2URCILOwtNsVLKlIWyoChSotDYqFHIgsXMLEYNxuLez8z75rl8z/vee8b719d9vXPPOfc777x7zr10KIVDeIxxfMPm1i6nKQxhGh9xCxuKGtiI75jEVZzG6sat7ycHcBkPMIEZXG+h7QrO4U6c/6So06NR8VhRxYI8j34mMaqxgftb20+F5FmeFyxKKPXFcbSAo3o4IfwdenCkzWy/RhdW5gWLE0rdcZyuw2ER7rWx7ezdu/OCVMZ1SJAKXG8cp5qxkDblSxxX5AW/ClwXdgib6duSFvUvMBbHSl6QD9wALgoleAuuCP1MyvBMgadR1bJZXBMS5wJu4AzWM784DOB4/PxS6IFSvDGbzn/ChwJz24H3OItLOBi/u2s2E6vowR5hb3unRkUpkYryMrMe27uizkNswpJMUGuPm8AIbmIN+utc6EJgZxyH8Mqc1ixVVbOi0JeY0yqGhUw4XLKfrPEdywtSDXAW3bJ7vb3xYfYsvF0IDnzCyZxOtqavJdiux08Vg8KvWimiVAdD0pV4rIbOM2FLmXcUaoDtuQzHeet+M6+KU1FpXxGlJtArXHGdb4KvESEGq4oo7Y9Kt7FW+xzPdgstUBlXXBlLsU24hxxX8N2X4YXq1P5fLjLnvvNgrUmp4jCFrUJJ7hfupFKniIXCfaEYfMYj4U6vQ4cW8wOo/5Y5FpjzqAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left\\{-1, 1\\right\\}$$"
      ],
      "text/plain": [
       "{-1, 1}"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(x**2-1,x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从上面可以看到，如果等式等于零，那么可以使用$solveset(expr,x)代替solveset(Eq(expr,0),x)$.\n",
    "### 8.1 解代数方程\n",
    "求解代数方程的主要函数是solveset。solveset函数的语法是，solveset(equation,variable=None,domain=S.Complexes),equation可以是Eq实例形式或者是等于零的表达式。\n",
    "\n",
    "需要注意的是，还有一个函数solve，也是用于求解方程式的，语法为，solve(equation,variable)。通常情况下，推荐使用solveset函数。\n",
    "\n",
    "当求解单个方程式时，solveset的输出，有多种形式，如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAD0AAAAWCAYAAABzCZQcAAAABHNCSVQICAgIfAhkiAAAArZJREFUWIXt2E+IV1UUwPHPZBhZ6pgLXTQ0aGMoLiRCbSFMk0EggWFtXLVOFAkXYogjEYo4orkRFzbouHGl0KJchCD9IbCCAssIx4VZUItptClHs8U9D37z/N33mzd/lNAv/Djze+ece+753fvuOXd4yF1sxJcYwm2suL/TaUkvRvErTmNJ3QGW4V8M4xjew8Imdk+H/hf8g0EcxLz6cx7DGziM8/gTdzDQwqcbe/Fx2H9VN+imcNxSYbMYv4Xd6Qj4aXz/AfPrBm3g2xhnGBeNL+lGLkiL9mSdoDsj0CsVNp+EzebS8wPx/EidgCVeQhfapBWsm/TJ8OmoE7Q3nLoz+kWhv4xHSrrZuI4beKJO0Azd6ifdHz6dZUV5snXoCXlW2kaNDOMzzMLqScSYFqqSbg85ktE/F/JSRv9TyNon6BTxd8i5ZUUu6TaskbbHlYxNMdhQRl88b8/op5vBkN1lRTnpV9EnHfXP46hU8yZCW8g7E/SfLCekBduPU3hfvN/Nkn4HL+B7qU7mKFbyru0TzCnZ3WuuYo/UrLyJHTJJb5WSWI9npZI0IzPojyFz72xXyNw7P92sk0rm11iOmTjXymlA2prLM/rFWpesv9y/ktUXPmvLiqrTuzjAnsrof5bKVafUvTWyW0r2uFSrG+mPybxVEXsqKNrgwbLi0Qqn0ZBVP8zb+Bwf4GWpXVwldVOX8G4Tn2K8WxXjkl6x9fF30fO/KP1o8Du2VfiPN84YdqnuyAo68CGu4aa0Qw7J75BvpAtEqwtJb8TPfQZb+PeH3TMt7MawPZxer+PUgnbpirpvCsfMcUaa/4I6ThvC6SNpNSfTsha8JnVKza6oU8VjWCmVyiE15/04vjN2S/0f/onQON9dzYyqDrIRqUnpwVLpXjrR7uxecU46uP7AF9Kd/CEPLP8BkjSiZ9m8MK4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left\\{0, 1\\right\\}$$"
      ],
      "text/plain": [
       "{0, 1}"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(x**2-x,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABAAAAARCAYAAADUryzEAAAABHNCSVQICAgIfAhkiAAAAR1JREFUOI3d078rhVEcx/GX68ekLuoqhUFRJqUYSBY/FjIZlbIb/QEK5UfJJoNJiclGKMUgZTJYGNgMGC3IcA5dzz13svnU0zmd9/d8nuf5fM/hj6pIrI1iEy9ow10Rq8EnFrFXznQFfejBcoLvYwuDkEsU9OIKIzjOsJq4ZwlTKYNGPOMdA7jI8H5c4glNKYMhnKAWH3jL8GGcogv3ia+3jXaMYS7Bj+JvHKI7ZXAex41MQSU6cBNNpr9BVVFRJ27jvF8Isw55PEa+hh2/W/ujWUyiBbtxLS8EWYFVIYOyOkADZuLzrQVMoCAEnFS1kK749tYiVsBZkdl4ymAgwpzS3sO6cLDqo1nJFZgXgrkWOpBVMx6EQ/QqZPVf9AXcdTMJAEiwkgAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\mathbb{R}$$"
      ],
      "text/plain": [
       "ℝ"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(x-x,x,domain=S.Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL4AAAAXCAYAAAC1Z/W7AAAABHNCSVQICAgIfAhkiAAABhNJREFUeJztmn2IFlUUhx9Xba1Wy6QUIjTbxFLItA+CkldFMiW/IiX/SMPAIiqJMknEIc1KiCwivyotS6L8TEpD0AU3i8rSRA0VWkNIS6ksNLN6++N3p50d587MnZ3dV2weeJl577lz77nnfp1zZ6CgoOAMJgCfAb8CfwP9KqtOQQweUAZ6VFaNiuIBp4HDwFqgV5ZCrgX+AX4D3gBmA90C8i7A/cAa4ABwEk2QemAyUJVJ9XObrmgBedn8z9OGHpUd+N2BOcDXqA1ly6+uBXUoAc8BG01dn9sytospZBDQBphBY0cFuRtYAPwAbAG+Rx07FngNuMPkKbtqfw4zCg3mNeb/uWLDR4F5wHlosK1Ggz+KAwlldQI+RmMvig5Ab2AHUA30MfWCJlWdud8O3ADUAL8n1NmEmcjgQy3ywcCdnLkqdUMdWAbucqmwlZmEdCy1Yp0bgKNAW/M/Txt6VGbFn2Pq3Ya8hJakPXJhRiEbrgLGWfK+Y/S6IkoYt5X6nXPaIt8MrEfuUJDDwEJzX4p4bqhR6FmgL7ACOIJm5Tbg5lD+Edi3zfCvNWKQrPpchAb6euTuQHYb5oFrP0RRAp4CNgEDgT0toaihCngLWAl8ALyOFpL3LPn9cds2Shjn6jQHv9K/ImTXm2sv4AtktDfRljUcNaoWxRagLXMB8CCwGzXcpzcwHvnEm4BvcmuBnaz6jEBb8uqU9cTZMA9c+yGKacAJ4N4W1BPk9iwGtgJvAy8Bu5A7mDvz0YqQZuYHaYeUKgO3R8jfNbIfgf4h2Sojuy2UPsakzwmlTzPpkx11hOa5Oln0eR+tph1SlJ9kwyg83FydLP0QpCPauRanrK85zEc7C6ids1M8sxC14boooW3Fb4MaXQYOOqmoqLov8BEKUsL4K819wFch2V5zDQ8O32XYEUrvb0lvaVz16QAMQ1vzHynKT7J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4FBWcrdSiYPQZ8SusfdRdUgBJa8S6urBoFBQUFBQVnE/8CUe8Q81Hl3yoAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left\\{2 n \\pi + \\frac{\\pi}{2}\\; |\\; n \\in \\mathbb{Z}\\right\\}$$"
      ],
      "text/plain": [
       "⎧        π        ⎫\n",
       "⎨2⋅n⋅π + ─ | n ∊ ℤ⎬\n",
       "⎩        2        ⎭"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(sin(x)-1,x,domain=S.Reals)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果代数方程没有解，那么返回一个空集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAABIAAAATCAYAAACdkl3yAAAABHNCSVQICAgIfAhkiAAAAWBJREFUOI3V07tLXEEUx/GPulnxkajIYgJ2CmnSCBH/ADvtLBQFQTBt6lSmCjYhTRIsbERIGQQLC4VA1M4HIoiFj+1CJAna2GhCNsWM5O7l3sXCxgMHhvM7850z58xwR9Zwi5wCulHBVSLeEff/rrW5DhPYiImV6N/wDsPYRmctSBfW8BOzeI4SnmIKuxH6uhakiB2s43GGXsAXrOAvRvJAsyijPUd/j7dxPY8faEonNeEc4zmQKaz6P6A2XOJFOnEoCsUMyAAOhEklbQHLUJ8I9uAY16nkJ1jEKC5S2n7cVwUqRE9aIz7jFQ4zKv0TvQpURi+aE7E5oS/LGRB4hpN08JHq5r3EkvA4s6xZuOpYlvgBZ1HcQ2sOBD4Kt3iQJT6MpVaESWVZPWaEf9efd0oRX3GKX3iDPmHsPZjEFr5jMA9Sh09Cj4qYxmY8uSJ8iaNYTSkPcgNqyYl3CU/hHtk/FohEnA7Pes4AAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\emptyset$$"
      ],
      "text/plain": [
       "∅"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(exp(x),x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果不能找到解，那么返回一个条件集合。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAAAYCAYAAABa3SD0AAAABHNCSVQICAgIfAhkiAAACHpJREFUeJztnHmMXVUdxz9TljJCmaJSF7qFNg0FsQW1hiJkZAkVpKgooYrJM2CjLFYwGCohHcPSIlBaBSkF6qioqbYRhJCxilwsQlnqkpalxJbB2I5YqSxKbWsZ/vj+LnPfe3e/581gPd/k5r13zu/8fueec+7v/JZzH3h4eHj8n2M+8O2h7oSHh8dbC58F1gAvA7uBqS2SEwB/bBFvD4+hwg+AvwP7V+DxAaAfONdJjwYPXcAu4G/AXcCkogwOB14HXgWWAVcC73bXvzoEDJ0CGgdcBfwBKdr+hCsYov55/G/ig+j5ucQBr58DfcABDniVxWikB7YAO4BeYBFwUAJ9J7AA6EHPz2NxRG0pAi8AbgLm0Hr3KABG0joLKwlzgG8B+6IBegopoTj8GY1HHnQC5wAfQpbjK8B/0X0uRkrdY8/GKmAa8B5ge0Ve04BHgcuBayryKoMJwMPAKOBu4Bnr00eBDcCxwIsp7dcCRwEHAv/KK/QKpLlOLtXlYggYfAvoKnR/DyNrzwXeDtwDrAZOaKhrA04HfgdMzMmvDViIFN/nHfXxrY4ampfOoe1GJUxC1s9ShzyfBp4H9nLIMy9+iebkoobyhVa+JKP9j4xuTBGhXWQvhFVG86mG8jag2+oW5JAVUEwBVZXbiRbIKmDvAnLTMArtUvcBR6fQTTa5w3LwPIYBF3BT1Q62AK7mP4oa1RTQNGA5sBm5Cn3Wz7NiaM8Cfous3u3AOmAuMDyB90zgfuO5A7kjDwLnN9AtsHs4MYFPmXGbZ+WnJPBsFQ41uc/RvGZHIIvm36THubq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left\\{x \\mid x \\in \\mathbb{C} \\wedge - x + \\cos{\\left (x \\right )} = 0 \\right\\}$$"
      ],
      "text/plain": [
       "{x | x ∊ ℂ ∧ -x + cos(x) = 0}"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(cos(x)-x,x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在solveset模块中，使用linsolve求解线性方程组。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL8AAAAXCAYAAABapZ6FAAAABHNCSVQICAgIfAhkiAAABMxJREFUeJztm22MHWMUgJ+tj3atqCI0K6o/KEWC+Kj+aDMorUijlD/++ExDSqlK0KAbUl/RIBVZJM2SNkG22iqJIKhuo75SScv+oMnSD6VCq9Eli/XjnMnM3p33Y+69c2duO08yubvznvOeM+eeeee877wXSkpKErke2AjsBf4FzjHIvQr8ArQ1yK+Sg5fzgEHgFotMBzAA7AJWAxPSGjkD+A/YBywDHgXGJsidr3L3pDXQpFwLLAXWA38gX8TyXD1qXo4FbgVWAd8D/chA24Mk9wiD3irgJ+BIQ3sAPAG8i3w/n6d1bK4qznPIvQfsAVrTGmhSvkbisg/opUz+WrgNid9OYAXwODLQ7tHz3UBLgt6F2r7Qw8ZXyOBsulESeUgNXGaRmaAdv5Sm4ybnYuBU5EsJKJO/Fi4BZjJ8hB8L/IjEdrZBtxf4ATjEYWOF9nNSZYPpsUKs0wGLzM1IErzucKBaFiCOLzC0nwb8DXySkf0kPgK+Q/wqMkWMXSUfAmuRATTOLqBT/w4Muq8B44BpDhth/g67SWzJ78M0ZCK8scZ+TPTo50WG9qXIRd2Rkf1mptljFybtP4b2Dfppq0yq5llk5JhkaG9DHNuchXHlMGA/8gis5DrEv+cytO8ioLhlT9FjZ+NQJK8GgekGmdH4TWY7Ve5sX+MtRBOFpBUekHp/EJnwZsk6tdMeO9cGbAN+RoKQFwHFTX4oduxsPI34/Y5Drh8pkWzcr33d5TI6A1gCfKEKnRbZySpjq/f7VMb3SEqix7Ttmti5J/XcjfbLqZsPJoIqdBpJrbHLg3mIf73AMQ7ZHZjLopATkRwYAN4AFgPjQR4vcWYQ3SFbkLrQRL9+jrLIbAX+cjgXZ2fCubC2mwS8CZwOzAc+BV7x6LMePjQrtcau0cxFSrFvgUuB3xzyrUR5aGIHsoT6DFLuAbyP3BDDOAq4SjvdjnkpqR25Q3sM7fViDFJ+rdP/P0Am2edmbNeHgGKP/EWOXSV3I7HcDBzvIT8CubatDrkrifL0TGQu5GS5Kp1laG9BtjTs9umsRr4B/kS2WwwCLzTApg8BxU5+KG7s4tyH+LYJOM5TZ6LqrHTILVE515LoEBar0lSLTLfKnJKm4yp4keit6m7ctWCjCPBL/i7yq7N9Y9dFPj6GL1O/JN33epPquZZql2HI0cqaP064zmp7F7ASeQM3HdmbkRUbgDnIK+r5uGvBLJmlB0QrYZOR5AH4Fbi3QieMoWtylgW+scvDxxuAR5BSbD3JW2n6iGIb53LVW+OwUdV1LULumMAicziy1PRZmo6rYArRmm7SXo9G0oF9tagvQWcTsgluTEM8HIpv7PLwsQP36tvHCXqjkTnpag8bXdrPyWkcC9dHr3bIPaByWU6i3kLu8gsytJEVRyO+P5WTfZ/Y5e1jWu5Ecm6Kh+walT0hjYHZqvQ2sinIVP6MQjYYrU3TeQrCidrzGfWfNTORpVbTy8Is8Y1dnj6mpRVZju52yI1Edn/u1SPVVp5WolfM4WH6MctUpEyq149ZxiFPnpeRzVdbgCPq1PeBzoEeu4lIuTTeItPB0LxdVI2hkcAVyA9VHqZxI8McxOnfkbdy7Xbxkhhl7GSe+iBwO+YBu6SkpKSkpKTkYOF/8H5qxbzw1ooAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left\\{\\left ( - y - 1, \\quad y, \\quad 2\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(-y - 1, y, 2)}"
      ]
     },
     "execution_count": 193,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方程列表形式\n",
    "linsolve([x+y+z-1,x+y+2*z-3],(x,y,z))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL8AAAAXCAYAAABapZ6FAAAABHNCSVQICAgIfAhkiAAABMxJREFUeJztm22MHWMUgJ+tj3atqCI0K6o/KEWC+Kj+aDMorUijlD/++ExDSqlK0KAbUl/RIBVZJM2SNkG22iqJIKhuo75SScv+oMnSD6VCq9Eli/XjnMnM3p33Y+69c2duO08yubvznvOeM+eeeee877wXSkpKErke2AjsBf4FzjHIvQr8ArQ1yK+Sg5fzgEHgFotMBzAA7AJWAxPSGjkD+A/YBywDHgXGJsidr3L3pDXQpFwLLAXWA38gX8TyXD1qXo4FbgVWAd8D/chA24Mk9wiD3irgJ+BIQ3sAPAG8i3w/n6d1bK4qznPIvQfsAVrTGmhSvkbisg/opUz+WrgNid9OYAXwODLQ7tHz3UBLgt6F2r7Qw8ZXyOBsulESeUgNXGaRmaAdv5Sm4ybnYuBU5EsJKJO/Fi4BZjJ8hB8L/IjEdrZBtxf4ATjEYWOF9nNSZYPpsUKs0wGLzM1IErzucKBaFiCOLzC0nwb8DXySkf0kPgK+Q/wqMkWMXSUfAmuRATTOLqBT/w4Muq8B44BpDhth/g67SWzJ78M0ZCK8scZ+TPTo50WG9qXIRd2Rkf1mptljFybtP4b2Dfppq0yq5llk5JhkaG9DHNuchXHlMGA/8gis5DrEv+cytO8ioLhlT9FjZ+NQJK8GgekGmdH4TWY7Ve5sX+MtRBOFpBUekHp/EJnwZsk6tdMeO9cGbAN+RoKQFwHFTX4oduxsPI34/Y5Drh8pkWzcr33d5TI6A1gCfKEKnRbZySpjq/f7VMb3SEqix7Ttmti5J/XcjfbLqZsPJoIqdBpJrbHLg3mIf73AMQ7ZHZjLopATkRwYAN4AFgPjQR4vcWYQ3SFbkLrQRL9+jrLIbAX+cjgXZ2fCubC2mwS8CZwOzAc+BV7x6LMePjQrtcau0cxFSrFvgUuB3xzyrUR5aGIHsoT6DFLuAbyP3BDDOAq4SjvdjnkpqR25Q3sM7fViDFJ+rdP/P0Am2edmbNeHgGKP/EWOXSV3I7HcDBzvIT8CubatDrkrifL0TGQu5GS5Kp1laG9BtjTs9umsRr4B/kS2WwwCLzTApg8BxU5+KG7s4tyH+LYJOM5TZ6LqrHTILVE515LoEBar0lSLTLfKnJKm4yp4keit6m7ctWCjCPBL/i7yq7N9Y9dFPj6GL1O/JN33epPquZZql2HI0cqaP064zmp7F7ASeQM3HdmbkRUbgDnIK+r5uGvBLJmlB0QrYZOR5AH4Fbi3QieMoWtylgW+scvDxxuAR5BSbD3JW2n6iGIb53LVW+OwUdV1LULumMAicziy1PRZmo6rYArRmm7SXo9G0oF9tagvQWcTsgluTEM8HIpv7PLwsQP36tvHCXqjkTnpag8bXdrPyWkcC9dHr3bIPaByWU6i3kLu8gsytJEVRyO+P5WTfZ/Y5e1jWu5Ecm6Kh+walT0hjYHZqvQ2sinIVP6MQjYYrU3TeQrCidrzGfWfNTORpVbTy8Is8Y1dnj6mpRVZju52yI1Edn/u1SPVVp5WolfM4WH6MctUpEyq149ZxiFPnpeRzVdbgCPq1PeBzoEeu4lIuTTeItPB0LxdVI2hkcAVyA9VHqZxI8McxOnfkbdy7Xbxkhhl7GSe+iBwO+YBu6SkpKSkpKTkYOF/8H5qxbzw1ooAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left\\{\\left ( - y - 1, \\quad y, \\quad 2\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(-y - 1, y, 2)}"
      ]
     },
     "execution_count": 194,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 增强矩阵形式\n",
    "linsolve(Matrix(([1,1,1,1],[1,1,2,3])),(x,y,z))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 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3sM7fViDFJ+rdP/P0Am2edmbNeHgGKP/EWOXSV3I7HcDBzvIT8CubatDrkrifL0TGQu5GS5Kp1laG9BtjTs9umsRr4B/kS2WwwCLzTApg8BxU5+KG7s4tyH+LYJOM5TZ6LqrHTILVE515LoEBar0lSLTLfKnJKm4yp4keit6m7ctWCjCPBL/i7yq7N9Y9dFPj6GL1O/JN33epPquZZql2HI0cqaP064zmp7F7ASeQM3HdmbkRUbgDnIK+r5uGvBLJmlB0QrYZOR5AH4Fbi3QieMoWtylgW+scvDxxuAR5BSbD3JW2n6iGIb53LVW+OwUdV1LULumMAicziy1PRZmo6rYArRmm7SXo9G0oF9tagvQWcTsgluTEM8HIpv7PLwsQP36tvHCXqjkTnpag8bXdrPyWkcC9dHr3bIPaByWU6i3kLu8gsytJEVRyO+P5WTfZ/Y5e1jWu5Ecm6Kh+walT0hjYHZqvQ2sinIVP6MQjYYrU3TeQrCidrzGfWfNTORpVbTy8Is8Y1dnj6mpRVZju52yI1Edn/u1SPVVp5WolfM4WH6MctUpEyq149ZxiFPnpeRzVdbgCPq1PeBzoEeu4lIuTTeItPB0LxdVI2hkcAVyA9VHqZxI8McxOnfkbdy7Xbxkhhl7GSe+iBwO+YBu6SkpKSkpKTkYOF/8H5qxbzw1ooAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left\\{\\left ( - y - 1, \\quad y, \\quad 2\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(-y - 1, y, 2)}"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A*x=b 形式\n",
    "M=Matrix(((1,1,1,1),(1,1,2,3)))\n",
    "system=A,b=M[:,:-1],M[:,-1]\n",
    "linsolve(system,(x,y,z))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在solveset模块中，使用nonlinsovle求解非线性方程组。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [
    {
     "data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SR5bHXx4RLk0cEe4GHt54yLYZuR2+l1hvoaEoSTLp0VRMSFt9wMJcLdFz0quzVQly3Ws8hOp/9OOVL/eWx18eE6lVmYVmnLRsaJkUsN9UPAR8ga9mpLP+2gF7FvWXvNKA1xKvvDxPFe3Pxki/UhJJXejbx11MxzyIW7if9nMV11F0morWD2YTPx616NtMrkMrKZ+PZnG5BbgaXIg77vLHJ5uFd/MPxu5jwkWACngJWJNrHN/7TIpnYR4guARchWYHviuI+fbLF+BPgEeAVZPvcDtyDbkYPA0yn9tStGIbaC2YfNBJ9T/MQ8ssiMQbKVn/l27kEdexavkdJmH/Kibhlfgs1DHX9fTEI29X0pdT5+yor1NOBN5PHA38jK6GXMK6N2xsjXVpsPm+lF4jDD16BV2vC+DLknVe56XwUtYjIyA73UbkNKwnIkPvMTx0P8VFSsz7cYmXyYZLvKXeGrYKk23IHMBKbl5DhkZnjPV0GLuAdJuad9DtRpdCGPFN5NqQvxU1GxPp9iZPNhzFjky4AB/Xm/BtkFHODcZYrp49EFyLKzDBmnimF6kKVnd4F9dlqss3xY59wxstrUUc1UoYxFXt7sQb7Rsb1RUlHRiUTAbcCPwKfIN4cVFRUVFRUdwFk+AopWSB11ZQAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left\\{\\left ( -1, \\quad -1\\right ), \\left ( 0, \\quad 0\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(-1, -1), (0, 0)}"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 当只有实数解时\n",
    "a,b,c,d=symbols('a,b,c,d',real=True)\n",
    "nonlinsolve([a**2+a,a-b],[a,b])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHQAAAAWCAYAAAARprh2AAAABHNCSVQICAgIfAhkiAAABBpJREFUaIHtmWmIjVEYx39jn8jYQmQr1OADWaL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18xyUnb9rlokLuDHJC3NPSlC8W4/axI4Q7UZ9UvI4LqssVdgKxbTvj4uld1dPHh/YWVKjjFh7dKef3CGjCgBTJCt9SCrnRhIxJvt1rWu1j1DvPhnVReu7AGpqngKeQg2FZ6myDzbUlYAwZMQDbW2bytiSG3M7WJfOR25oiD0xi5kanUT+hj23xkuZ1aKmwX3MOREp274I6GQqRUd7X0F/NnHtbaFPndRzZGbhMKkfu3XcicmUNm4QFDgXfANWq/QuSQQw4ZwW928DB0TJbpWwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left\\{\\left ( 2, \\quad \\frac{1}{2}\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(2, 1/2)}"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nonlinsolve([x*y-1,x-2],[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW0AAAAWCAYAAAALk82UAAAABHNCSVQICAgIfAhkiAAABQ5JREFUeJztnU+IV0UcwD9apMsGagUFkXoIbbuUJlJQsqmVEB0iOtQp6tAhKvFkQboQUgTRoUt4iCUqNJJc6tCfQ1BIVpRBfxaCaD2YYgSZhMFW2+E7j7c9Z+a9N/Pm7azv+wEZdebNfL+feby3v3nzewuKoijKBcODwFHgDPAPcKOj3WvAaWA0URy7gDnggUT958b8fG8yf3+kw/6HNF/VWPr2mZOL1KjrkrYuJoBZ4BRwGFgXMuj1wL/AWeBV4FngKku7TabdrpBBGvImknBQIouQar7vACeBSzvoe2jzZYulT585uUiNui5p62IceB543xz3Rcigj5mDn6hp9yHwOzASMkhDVgPXAUsSjpET1Xw3I3PxdAd9D22+bLH06TMnF6lR1yUxLr5Cbk6tb3TPmAHu8LRZZzrf37ZzpTXTwHHgoog+dL5K1Gd/qOuSJi7eQK6919gql3oOLDqd9bR5GLmTHPS0ieV2JIE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x9vnw+Q2Jt4zM3F6lZyHM3N9d1LkCWVzYjv7/gDAFfFBpB1mbmb7B3/RKELchySqqX6g+ZMeQp8toO+xzyfKnP/lDXJXUuJvj/tXavq6O6984uQ7afjCHvdt1P+FdRFUVRFDvjwK3Ab8BnhG+PVBRFURRFURQliP8AgXY7PPj/MwUAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\left\\{\\left ( - i, \\quad - i\\right ), \\left ( - i, \\quad i\\right ), \\left ( i, \\quad - i\\right ), \\left ( i, \\quad i\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(-ⅈ, -ⅈ), (-ⅈ, ⅈ), (ⅈ, -ⅈ), (ⅈ, ⅈ)}"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 当解为复数时\n",
    "nonlinsolve([x**2 + 1, y**2 + 1], [x, y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAf4AAAAdCAYAAABLyA69AAAABHNCSVQICAgIfAhkiAAACK5JREFUeJztnXusHUUdxz99SCkXaKVAFFBMsNWiEYHGiI2wF2hRlARihZCYoEKiBiQGXxFDvIoPUGMQixaj5IZQtYEGCPLQP8QEBDVgm6BUg5irkUcEBQSsinr94zdLT0/3MTuPM7Pn/D7Jybm5Mzu/md/3d3ZnZ2dmQVEURVEUZYBp4LLUlVCUMeJo4IDUlVCisAZYFrF8jZ3JxTa2Pguc4mpkCbAV+BKw3LUQRVF24xDkNzVq9gPWAfMBP31jP8K2v8oHewMbgUUR6u8aO6No96STU2ytAL4A/BDYp2tDvghc2/UgRVFqWYD8GA9MYHsDHncBY8KofHAicuINiU/sqPbxyTG2NgJXdCl8EfAU8K6OlVIUpZ4zga8msr0R2CuR7VwYpQ/uBg4NWJ5P7Kj28ckxtk4FnkNGCnZjYc0BK5Hh/eedq6YoyiCLgUuB2QS2F5nP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ypMd4U02Ztr5q0rmtXjnpNEM6Hw7yZlo20giAbX1mcNOvfHPhpoo0yON3mNIHV9O+lWqs2FHt45N7bJWch8NeO2uB37Dr7qiKTyEVbJtxOgqWIz2rSdhC0oYPI9q8tSKtq69C6twnnUL6cJAzyHepoy990jcGa2nf1GZcY2fStY+NTWyVHIS8NdBpx9G1yOL/y2vS90ZeYHKLS+GBOQ1ZwtHUUZkUliJLVG6oSe/qq5A690Wn0D6cFNQv7Yyrj8a1XX3jYuRcfZJvQU1DC8cjrwic8jWiBGM1Msz0qoBlTprOMXyoKIoSG5+3QSqKoiiKoiiKoiiKoiiKoiiKkj//BzMMGjY9SfrEAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left\\{\\left ( -2, \\quad -1\\right ), \\left ( 2, \\quad 1\\right ), \\left ( - \\sqrt{2} i, \\quad \\sqrt{2} i\\right ), \\left ( \\sqrt{2} i, \\quad - \\sqrt{2} i\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(-2, -1), (2, 1), (-√2⋅ⅈ, √2⋅ⅈ), (√2⋅ⅈ, -√2⋅ⅈ)}"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解为复数和实数的混合\n",
    "nonlinsolve([x**2-2*y**2-2,x*y-2],[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAF8AAAAXCAYAAABtR5P0AAAABHNCSVQICAgIfAhkiAAABAtJREFUaIHtmV+IVVUUxn9jlE1jOpaQTI0OKprVg1paL8rFP6lEiIgvPgWFYWlQPpia44iIZinmP9KgBv+8RJGWDypSFGOoUUEliiGNEGka6mhqOdb14Vsbb6ez975nnLlzH+4Hl80537fXXmeftfdaZ1+ooGwxCzgEtAH/ACM8um3AWaCmRH51Jx4H8sDzAU0T0A6cAXYBQ7MO8gjwL3AZeB9YDvRP0T1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gxDEeHjg0BTRP/nbelHXGwJzAV/VHSSOkjsisxG03MBfTlWReWZ0IOVUtz8AdsBRVUUEGpcROjHe96+tg38QAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\left\\{\\left ( 0, \\quad y\\right )\\right\\}$$"
      ],
      "text/plain": [
       "{(0, y)}"
      ]
     },
     "execution_count": 200,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nonlinsolve([x*y,x*y-x],[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAANYAAAAWCAYAAAC8C2KaAAAABHNCSVQICAgIfAhkiAAABOtJREFUeJztm1uIVWUUx39nrJxhymMXKCpLNISpILtQESmn0hIiIqyXHiKrF0sNqocuhBMhimXZFevBDmU+hOJIPphSEWRZEAUFRiSNUI4WXSa7O2oPax3muN3fbV+Pzv7BYc/stb7vW99/nX351t4HKioqCud2YDswDBwAphv8Xgd+BHoLiqtsLgUOAXdn2OdY07AT8clrP7Af2AMMANNCBzkfOAjsA1YDTwJnxPhdpn4PGPo5W9vvBv4FBoGVwMmhAeVMaJwbgCHgxAzGdmlYURyuvDaAZcBm5CD8NHSA+7ThIoffFuA3oCfGNhXYq/0MaEDv6f9fA6eGBpUTSeK8XO2PZjC+TcOKYgnJ62fICTHo5Pq4DjDb4jNNO37VYH9H+1gY2f+M7l8VElCOJI1zB7ALGJdibJeGFcXjm9c3ke/HpJDO+7VRw+KzTH2ui7FNUdt3QFfEdhLwB/An5a8p0sS5WNvekGJ8m4ZZsU3HMH0+yHHsTiFEA9+8NtVvctRwXMpgZyFFje0xtmt1uwU5I7ezD5no9cCVwLsp40hDmji36XY2ctVLgk3DrNgAbI3ZPw84B3g/x7E7hRANssirkZXI0XiFwd4LjABfGuxPafsHDfYX1T4/RYxZkCbOOgkXsIpLwzxpzfs1jrxSjxVMGvjmdZX6XRQ1mAStATO00S6Dz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right )\\right\\}$$"
      ],
      "text/plain": [
       "{(0, 0), (-z, -z)}"
      ]
     },
     "execution_count": 201,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nonlinsolve([x**2+x*z,x-y],[x,y])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8.2 求解微分方程\n",
    "使用dsolve求解微分方程。第一步，需要创建一个未定义的函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [],
   "source": [
    "f,g=symbols('f,g',cls=Function)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "f和g是未定义的函数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAADcAAAAhCAYAAAB9VDPAAAAABHNCSVQICAgIfAhkiAAAA0ZJREFUWIXtmF1ozWEcxz/bam2GlZLImrL2cmFrNivyUixEXHhJy8VouWFcSF7mwpLaChdzo22l5WaIqCWakvISQ15WlkQoxlwMxTDMxe937H+enf95/s85Y6zzrdP5n9/r95zneX7P73cggTBUA10jTSIIkmPwKQLuDzeRP4FR/eVsyAMuA1+ATqAM+AwsGUlSw4Fc4APQAOQAy4EXwAAwySHOeOAI8Bz4pv67VHcc6AEy4uBZojGrXJwuAa2G7BjQ7Zi8TZOfBw4AtUABUAr8BLY7xouEs8prbBDjLCU0y5A3ARcckuZrnIsRdO3AeyDdIZ4fyjRPTRDjlcB3INWQ3wXqHJJu1qSbDHkusmpNDrFs6EKOTYrNcIWSGueRLVDZugCJVqttpFc+UK/Pi3z821W/ypAnAS2qqzd0+1RuLXZTkArZCEwnvJjk2ZyBOcjZ6gH69blWCaQAd5Cd4VdIioAfwCPCV+Kwcoi04uWqOxSAH+uBl0AvcAXYD3wi+N2YglwbDw15BvLFOi3+LUp2g36u0c8nfThkqr4jIL+4MEOTtRjyXJW3W/ynAn3IFVLNYGEy64AXfcAbd6ruqFRC2wz5bAZXwIY6Bs/qdWCMxf4VsiuA2NqvoJip7/cMeZ++pwWI8c7zXIVs82hI98T/Db/KFssrhKtIufdWXJBiNQBcsxCtUP9utT9qsU9W+6cWu7iRBHwEHvvoeghfFRPLkFatE5iI3GH9yDXihwLkRzjjQjSW+S1PE53w0Z9WfU4E3Vxk+z0DJqtsjdqfi5Jzo9pUuxBtZmiPaUOFJtpp0W8x5EVIS9aN3K9e3FafeT4xW5FikuVCtIPBLj4oDiqRch99KlKyb3lkOSrrBQoj+IQu6ZsRdJlIIYm2slHnt7XAVyDbY98APEHOhSv2KNniGHxNbCX6qlrntySkbWpW+x3AW4Zun6BI0/htMfqHkA68Rs6xL4LMb4uRqrUbqYalcRKbj/Sb8QyrBUjfOs3PwGV+u4Ec3KVxEPorCHUoxUgX/sDQlxD+Z9BCpKIlI3fVf4Eg81uoTFciVcllIh9R2Oa3bKQp3av2hUir41ud/jX4zW8TkA6l0bA/hb0/TCCBBBIYHfgFNIvyexn5aWAAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$\\frac{d}{d x} f{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "d       \n",
       "──(f(x))\n",
       "dx      "
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f(x).diff(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASUAAAAmCAYAAACChI1tAAAABHNCSVQICAgIfAhkiAAAB2FJREFUeJztnGmoFWUYx39upZlpWpaSeSBx+aC2mJDYZpJmaZJFSIQnrBA1ESktI5KIDNLK+hBqhUmhhVEgLRiVloW5oCkoUcq1SMtKLShbXPrwvIczzp31zDvbvc8PhnvOu80z/3PP/7zLzAuKoiiKogTSB1gP7Aa+Bm7LNRpFUVo9vYCh5nVP4AfgrPzCUZTyMhPYk3cQJSVIu53AxR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T1xx1aM2roipICUTcmq92rMQVZ4rS5vWtZUUNXlBSIsjFZX+RJ50fN+yHIl6u1LRW7UUNXlJQI2pisO3LfzFJXnbcIf/izpaOGrihK4VBDVxRFURRFURRFURRFURRFURRFURRFyYX/AVug7Y8Jvp30AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$f{\\left (x \\right )} - 2 \\frac{d}{d x} f{\\left (x \\right )} + \\frac{d^{2}}{d x^{2}} f{\\left (x \\right )} = \\sin{\\left (x \\right )}$$"
      ],
      "text/plain": [
       "                      2               \n",
       "         d           d                \n",
       "f(x) - 2⋅──(f(x)) + ───(f(x)) = sin(x)\n",
       "         dx           2               \n",
       "                    dx                "
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diffeq=Eq(f(x).diff(x,2)-2*f(x).diff(x)+f(x),sin(x))\n",
    "diffeq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAR4AAAAYCAYAAAAs55J/AAAABHNCSVQICAgIfAhkiAAACHRJREFUeJztnH+MHVUVxz/LltqVarEooEGJoRSoKCqCAdRQJChNQKRCLH/IKEJI8QcSftg2hA1RipRapGLlh1iNiC0lkBAjFgiFgkG6tWihTaOUpaQstFgrKKW/eP7xPZM3O3vvzHvz673W+SYvb+eee8+cO2fOueece99CjRo1anQJ3g3cDAwCO4AGcJXRfg1sAvbLyPtY43dBPhELQ9751EhGGfo+B9gOHBpp+wnwd+B9Bd5nT8Meb5sPmAC/B34A9ANHAZ8C3gYuy8n/PmAIGJuTT160Mp/DgdnASmAzsNO+HwamA+8sWca86Ab5i9Z3DzAA3G7XlwOvAocVxH9PRNW2eRCwGwUoAAcA37Tx/wC2Af8GnkCObJ+0Gx+JnM6DDtpSYCvQlyp+Mo63e8zMyScvkubTA1yLVtYG8CSwALgeuBv4p7Uvr0TS9tFN8peh79OQE/0+8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8O3Sfa4VaGo+cRRhOPpFOaiVdmVPmRFt+h7b0bZthmevP5wTv6ZMAZV4B/IwaMPrQqtbjWXiSLm48Ke6nhupnin00363ptRtm2uJf2IQctot3C3C/gL+lHbAAqN28XhKCe+AeWgnUQR8wkxFhnswShUXoHC5NHoR4Hdjp8BX0Pnjzag+YT/k2VHDr7dpO+9GWXb5i2oflWjy3Ay2bb2uwW+vLy/gzLVqFGjRo0aNWrUqFGjRo0aNWrUqFGjS/E/GVluuEnvcnYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$f{\\left (x \\right )} = \\left(C_{1} + C_{2} x\\right) e^{x} + \\frac{\\cos{\\left (x \\right )}}{2}$$"
      ],
      "text/plain": [
       "                    x   cos(x)\n",
       "f(x) = (C₁ + C₂⋅x)⋅ℯ  + ──────\n",
       "                          2   "
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dsolve(diffeq,f(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL8AAAAXCAYAAABapZ6FAAAABHNCSVQICAgIfAhkiAAABgRJREFUeJztm22IFVUYx3/rmrm5tUUvKJkEmbn2or0gJCVGQuWH3hTJT90SpczUpAz1gxKllplSRFFWmxCrm1IgkUmRvQilLW1ZmR9a12K9tlvbWpjpprcPzzPcce6ZM3PnzJpe5w/DzJznmeecef7nnHnOc+6FDBkyHIOzgOeBNuAwUAAeV9kaoAMYkND2tWpvqlsTKwpRPu1NPsDOySnH10bkhd8DngQWA/XAdcBRYK6j/XeAPFDraKcSEMenvc0H2Dk50fi6FFgKNAOdQI+ePwRmAGckNTwccfQmg2wz0A3UJDWuGK11LHC0UwmI8unx4APsnJwofFUBTwCHkPZsBV4ClgGNwO9a/lnSCmaogWmB8mHILPNKUsMB7AT2ANUJn88h7RyXUnv+D8Tx6fHiA+ycuPKVBt5AfPE9MN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zozLTo25Egn2zPCIPdne8ZoPbs5NnavRt6vgGyseLiV0i8qFDNDt/nKwnwKyfmA3uHElS8XzNa6d2EevFWIX5ssNqydf4oqzIuQP+QrG4mEEHngkoC+t6i8McReI7J4usjSYBtyuOf5jyBpySbgKeBlJCb/OKDrpdp+BV4EnkFm1AKyle7PnnQjYcZ6JORYgaQHC2rbvydg8mlQVg4f0HucuPLlgiqKX84e5DdOKxEeGoFfVPaWxYa18y9XhfEh8n4IqV/q/VC9/wO4yqDvbYp8YZDVIQsn2ywUhRxunR8ka7IBCSEOI1mBTZiddA/wOfAX8A+yxb6Q0kXnA8gPwVqR2bcLWbDOo3RnMuhTP8rlA3qPkzT4SgMTEN+2I3x1ITw0IZkx2xrI2vnjYL4audrFCPAw9hnoVIKLT9PiA+ycVAJfzp2/P5LX3uhgowaZYde7NKSC4OLTNPgAOycnM1+1SEp8FNL5H9XrIUkNjkV+X5L0zxP1yJb2xUkbUIFw8akrH2Dn5GTmaxzJsksZMmTIkCFDhgwZMmSoAPwH0RlTReE14rgAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$f{\\left (x \\right )} + \\cos{\\left (f{\\left (x \\right )} \\right )} = C_{1}$$"
      ],
      "text/plain": [
       "f(x) + cos(f(x)) = C₁"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dsolve(f(x).diff(x)*(1-sin(f(x))),f(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 9 矩阵\n",
    "在SymPy中，创建矩阵，需要使用Matrix对象。通过提供构成矩阵的行向量列表来构造矩阵。矩阵形式如：$\\left[\\begin{matrix}1 & -1\\\\3 & 4\\\\0 & 2\\end{matrix}\\right]$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & -1\\\\3 & 4\\\\0 & 2\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  -1⎤\n",
       "⎢     ⎥\n",
       "⎢3  4 ⎥\n",
       "⎢     ⎥\n",
       "⎣0  2 ⎦"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Matrix([[1,-1],[3,4],[0,2]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}0\\\\1\\\\2\\\\3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡0⎤\n",
       "⎢ ⎥\n",
       "⎢1⎥\n",
       "⎢ ⎥\n",
       "⎢2⎥\n",
       "⎢ ⎥\n",
       "⎣3⎦"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Matrix(range(4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}5\\\\3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡5⎤\n",
       "⎢ ⎥\n",
       "⎣3⎦"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M=Matrix([[1,2,3],[3,2,1]])\n",
    "N=Matrix([0,1,1])\n",
    "M*N"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.1 基本操作\n",
    "### 9.1.1 形状"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 2 & 3\\\\3 & 2 & 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  2  3⎤\n",
       "⎢       ⎥\n",
       "⎣3  2  1⎦"
      ]
     },
     "execution_count": 210,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 211,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAVCAYAAADl/ahuAAAABHNCSVQICAgIfAhkiAAAAqVJREFUWIXt2NuLVmUUBvCfo8iIgqmVEoghMigEWkngRQl20Ju5EP+AFA0ED4QI0YA4BKFl4MWgF12EBF0EIxohghKE40CW8GmjDEKBJpPmYXDywg4euljv0Oee/X3u7Rw+LR/YbFhrPWs9a+93v4fNEzwUPscVTG60kDHAy7iHtUUJi3EXW6psM7AOB/ATbmEAx1PiphESO1L4CN/gotDajwq2i16yOIBLmFIk+RHcwKQq23rxlH/FF9iBz1LcPXRiXPk+Rg1/4TuhcSc68IPQ2ofZmfhXkq/tQYlbxOj5NGNfhlZDR8os/JKSryrTwSijuYb9Q6F1b46vFxcwvl7inSnB6yXEtCVORwlOo7BQaD2a49uefMurjdkR8QbuiOFZFH+n++0SnEahNd1/zPF1p/ubtciTRZM9JQpOSPFDnvwjgq1ox250CZ2n8UxO7NTk/75WspYUcKSEgE8S51AJzljistA3eB3GzDrxtxInF0tSki8LFt+c4nsxvSCnUZiJlTgnVuKXasT1qTNVLBINf1Wg4IYUe1asZI8L5uBPnKnh78fNWuTnRNPHH1Dk3RTXg2fLa2w4KkL/0xl7k9ji/FyLOE4cL67WSf5eSl7JKfC44DfRw7SMfUGy769H7kxB83J825LvpOJzzr7EWV0wfiQwX/5n3+TfjWJ3jn9N8m2sNk7IBO0XO+Ll4sw1iLfxgdgjdYkJOovz4oFkRTG2e6QV2IVj4nO5LibppZgrVql3cnhvif7qzsETU4ITGXu7+5fLvOvbnHwV/G7ocB5NvIA9OIVr4uUMiLNYu/zRP1Us8QeLFHhfNPziMIU+Jd7Ix8PMMxbYJHp+tUhwszi0fT3Moq34w6O/DZgk9kadZUivicPb/+GH2QLx6T3fWBlP8N/EP7JIpSDkxqvRAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\left ( 2, \\quad 3\\right )$$"
      ],
      "text/plain": [
       "(2, 3)"
      ]
     },
     "execution_count": 211,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9.1.2  访问行和列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 2 & 3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "[1  2  3]"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M.row(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}3\\\\1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡3⎤\n",
       "⎢ ⎥\n",
       "⎣1⎦"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M.col(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 2 & 3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "[1  2  3]"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M[0,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}3\\\\1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡3⎤\n",
       "⎢ ⎥\n",
       "⎣1⎦"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M[:,-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9.1.3 删除和插入行和列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [],
   "source": [
    "M.col_del(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}2 & 3\\\\2 & 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡2  3⎤\n",
       "⎢    ⎥\n",
       "⎣2  1⎦"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [],
   "source": [
    "M.row_del(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}2 & 3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "[2  3]"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}2 & 3\\\\0 & 4\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡2  3⎤\n",
       "⎢    ⎥\n",
       "⎣0  4⎦"
      ]
     },
     "execution_count": 220,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M=M.row_insert(1,Matrix([[0,4]]))\n",
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [],
   "source": [
    "M=M.col_insert(0,Matrix([1,-2]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 2 & 3\\\\-2 & 0 & 4\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1   2  3⎤\n",
       "⎢        ⎥\n",
       "⎣-2  0  4⎦"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.2  基本方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [],
   "source": [
    "M=Matrix([[1,3],[-2,3]])\n",
    "N=Matrix([[0,3],[0,7]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 6\\\\-2 & 10\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1   6 ⎤\n",
       "⎢      ⎥\n",
       "⎣-2  10⎦"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M+N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}3 & 9\\\\-6 & 9\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡3   9⎤\n",
       "⎢     ⎥\n",
       "⎣-6  9⎦"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3*M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}-5 & 12\\\\-8 & 3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡-5  12⎤\n",
       "⎢      ⎥\n",
       "⎣-8  3 ⎦"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}\\frac{1}{3} & - \\frac{1}{3}\\\\\\frac{2}{9} & \\frac{1}{9}\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1/3  -1/3⎤\n",
       "⎢         ⎥\n",
       "⎣2/9  1/9 ⎦"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M**-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 2 & 3\\\\3 & 2 & 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  2  3⎤\n",
       "⎢       ⎥\n",
       "⎣3  2  1⎦"
      ]
     },
     "execution_count": 228,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M=Matrix([[1,2,3],[3,2,1]])\n",
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 3\\\\2 & 2\\\\3 & 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  3⎤\n",
       "⎢    ⎥\n",
       "⎢2  2⎥\n",
       "⎢    ⎥\n",
       "⎣3  1⎦"
      ]
     },
     "execution_count": 229,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.3 初始化矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 0 & 0\\\\0 & 1 & 0\\\\0 & 0 & 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  0  0⎤\n",
       "⎢       ⎥\n",
       "⎢0  1  0⎥\n",
       "⎢       ⎥\n",
       "⎣0  0  1⎦"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eye(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}0 & 0 & 0\\\\0 & 0 & 0\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡0  0  0⎤\n",
       "⎢       ⎥\n",
       "⎣0  0  0⎦"
      ]
     },
     "execution_count": 231,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zeros(2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 1\\\\1 & 1\\\\1 & 1\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  1⎤\n",
       "⎢    ⎥\n",
       "⎢1  1⎥\n",
       "⎢    ⎥\n",
       "⎣1  1⎦"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ones(3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 0 & 0\\\\0 & 2 & 0\\\\0 & 0 & 3\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       "⎡1  0  0⎤\n",
       "⎢       ⎥\n",
       "⎢0  2  0⎥\n",
       "⎢       ⎥\n",
       "⎣0  0  3⎦"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diag(1,2,3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
